html-css:關於浮動的方式


1.在 The standard flow中內容的高度可以support父元素的高度
2.在 The standard flow中浮動的元素can not support父元素的高度

1.清除浮動的方式:
給前面一個父元素設置高度
notice:在企業開發中能不寫就不寫高度,這種方式用的很少

清除浮動的第二種方法: 添加clear屬性
none 默認取值(左浮動找左浮動,右浮動找右浮動)/left (不要找前面的左浮動元素)/right(不要找前面的右浮動元素)/both(不要找前面的左、右浮動元素)
Notice:當我們給某個元素添加clear屬性之后這個屬性的margin屬性就會失效。

<head>
<meta charset="UTF-8">
<title>clear attribute</title>
<style>
*{
margin: 0;
padding: 0;
}
.box1{

background-color: red;
}
.box2{
background-color: green;
clear: both;
}
.box1 p{
width: 100px;
background-color: blue;
}
.box2 p{
width: 100px;
background-color: yellow;
}
p{
float:left ;
}
</style>
</head>
<div class="box1">
<p>秦怡大傻瓜1</p>
<p>秦怡大傻瓜1</p>
<p>秦怡大傻瓜1</p>
</div>
<div class="box2">
<p>秦怡大傻瓜2</p>
<p>秦怡大傻瓜2</p>
<p>秦怡大傻瓜2</p>
</div>

 
        
 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM