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