CSS学习之清除浮动
来源:互联网 发布:ubuntu 升级软件包 编辑:程序博客网 时间:2024/05/29 11:41
浮动产生的负作用:
2、利用overflow:hidden
3、clear:both
5、给父元素添加浮动
当子盒子在父盒子内部有浮动效果时,父盒子由于没有合适的高度和宽度,父盒子不能完全包含子盒子,布局就会出现差错。
<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style type="text/css">.div{background-color: red;border: 1px seagreen solid;}.div1{width: 50px;height: 50px;background: #eee;float:left ;margin-left: 10px;}.div2{width: 50px;height: 50px;background: #bbb;margin-left: 10px;float: left;}.div3{width: 50px;height: 50px;background: #ddd;float: left;margin-left: 10px;}</style></head><body><div class="div"><div class="div1">div1</div><div class="div2">div2</div><div class="div3">div3</div></div></body></html>父元素不能被子元素撑开
清楚浮动方式:
1、对父元素设置适当的高度
<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style type="text/css">.div{height: 60px;/*给父元素设置一个合适高度*/background-color: red;border: 1px seagreen solid;}.div1{width: 50px;height: 50px;background: #eee;float:left ;margin-left: 10px;}.div2{width: 50px;height: 50px;background: #bbb;margin-left: 10px;float: left;}.div3{width: 50px;height: 50px;background: #ddd;float: left;margin-left: 10px;}</style></head><body><div class="div"><div class="div1">div1</div><div class="div2">div2</div><div class="div3">div3</div></div></body></html>
2、利用overflow:hidden
<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style type="text/css">.div{overflow: hidden;/*多余部分隐藏 贴近内容*/zoom: 1;/*兼容IE*//*zoom比例缩放*/background-color: red;border: 1px seagreen solid;}.div1{width: 50px;height: 50px;background: #eee;float:left ;margin-left: 10px;}.div2{width: 50px;height: 50px;background: #bbb;margin-left: 10px;float: left;}.div3{width: 50px;height: 50px;background: #ddd;float: left;margin-left: 10px;}</style></head><body><div class="div"><div class="div1">div1</div><div class="div2">div2</div><div class="div3">div3</div></div></body></html>
3、clear:both
<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style type="text/css">.div{background-color: red;border: 1px seagreen solid;}/*.clearfloat:after{clear: both;content: '';display: block;}*/.div1{width: 50px;height: 50px;background: #eee;float:left ;margin-left: 10px;}.div2{width: 50px;height: 50px;background: #bbb;margin-left: 10px;float: left;}.div3{width: 50px;height: 50px;background: #ddd;float: left;margin-left: 10px;}.clear{clear: both;}</style></head><body><div class="div clearfloat"><div class="div1">div1</div><div class="div2">div2</div><div class="div3">div3</div><div class="clear"></div></div></body></html>
4、:after
<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style type="text/css">.div{background-color: red;border: 1px seagreen solid;}.clearfloat:after{clear: both;/*清除浮动*/content: '';/*不会有内容显示在页面中*/display: block;/*显示*/
}.div1{width: 50px;height: 50px;background: #eee;float:left ;margin-left: 10px;}.div2{width: 50px;height: 50px;background: #bbb;margin-left: 10px;float: left;}.div3{width: 50px;height: 50px;background: #ddd;float: left;margin-left: 10px;}</style></head><body><div class="div clearfloat"><div class="div1">div1</div><div class="div2">div2</div><div class="div3">div3</div></div></body></html>
5、给父元素添加浮动
<!DOCTYPE html><html><head><meta charset="utf-8" /><title></title><style type="text/css">.div{background-color: red;border: 1px seagreen solid;float: left;}.div1{width: 50px;height: 50px;background: #eee;float:left ;margin-left: 10px;}.div2{width: 50px;height: 50px;background: #bbb;margin-left: 10px;float: left;}.div3{width: 50px;height: 50px;background: #ddd;float: left;margin-left: 10px;}.clear{clear: both;}</style></head><body><div class="div clearfloat"><div class="div1">div1</div><div class="div2">div2</div><div class="div3">div3</div></div></body></html>
阅读全文
0 0
- CSS学习之清除浮动
- CSS学习之清除浮动
- css基础学习之清除浮动
- css学习笔记之浮动清除
- CSS之清除浮动
- CSS之清除浮动
- css之清除浮动
- div+css之清除浮动
- css之clearfix清除浮动
- div+css之清除浮动
- css之清除浮动影响
- CSS之清除浮动clear
- CSS-浮动&清除浮动
- CSS篇之2. 清除浮动,什么时候需要清除浮动,清除浮动都有哪些方法
- CSS篇之. 清除浮动,什么时候需要清除浮动,清除浮动都有哪些方法
- CSS学习笔记9:清除浮动
- 学习笔记---css中清除浮动
- CSS学习之 浮动
- 【算法】3、堆排序
- POJ3090-Visible Lattice Points-数论
- 块元素/行内元素的转变
- 面试笔试--TCP/IP知识点
- 奇奇怪怪的东西们
- CSS学习之清除浮动
- 3-day(JavaScript)
- hdu1247
- Keepalived+lvs
- Git的详细使用(二)
- go by example之channel-synchronization.go
- bootstrap实现垂直导航框架
- 设计模式基础
- 如何在Linux上安装Mysql的二进制包(mysql-xxx-linux-xxx-x86_64.tar)