css中float用法
文檔流:瀏覽器根據元素在html文檔中出現的順序,從左向右,從上到下依次排列。
????
?浮動屬性是CSS中的定位屬性,用法如下:
????????float: 浮動方向(left、right、none);
??? left為左浮動、right為右浮動、none是默認值表示不浮動
??? 設置元素的浮動,該元素將脫離文檔流,向左或向右移動
??? 直到它的外邊距碰到父元素的邊框或另一個浮動元素的邊
??? 框為止
?
float用法(主要用于塊級元素的并排):
1、block塊級元素不指定width的話,默認是100%(即會占一整行)。
2、block塊級元素不指定width但加入float浮動后,其width會根據其內容長度動態改變,其他塊級元素可能會在其左邊或右邊加入。
3、block塊級元素指定width但加入float浮動后,其width不會根據其內容長度動態改變(文字可能溢出),其他塊級元素可能會在其左邊或右邊加入。
4、block塊級元素加入float浮動后,會脫離標準文檔流,向左或向右移動直到它的外邊距碰到父元素的邊框或另一個浮動元素的邊框為止。
?
示例代碼:
?
<!DOCTYPE html>
<html>
<head>
<title>demo</title>
<style type="text/css">
body{
margin: 0px auto;
padding: 0px;
}
?
.container{
width: 500px;
height: 500px;
border: 1px solid red;
margin:0px auto;/*主面板DIV居中*/
}
?
.header{
height: 100px;
border: 1px solid red;
float: left; /*加入浮動*/
}
?
.main{
height: 100px;
width: 100px;
border: 1px solid red;
float: left; /*加入浮動*/
}
?
.footer{
height: 100px;
width: 100px;
border: 1px solid red;
float: right; /*加入浮動*/
}
</style>
</head>
<body>
<div class="container">
<div class="header">
頭部
</div>
<div class="main">
中間
</div>
<div class="footer">
腳部
</div>
</div>
</body>
</html>
?
轉載于:https://www.cnblogs.com/wangzhaofang/p/8304172.html
總結
以上是生活随笔為你收集整理的css中float用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电视剧《传奇幻想殷商》的内容是?
- 下一篇: ajax异步传输数据时return返回总