您现在的位置是:css如南宫·NG体育何清除电子爆分浮动clear与float >>正文
css如南宫·NG体育何清除电子爆分浮动clear与float
满坐风生网7575人已围观
简介辨析它们的优缺点而已。六:父元素设置display:table<!doctype html><html><head><meta charset="u...
六:父元素设置display:table
<!doctype html><html><head><meta charset="utf-8"><title>MAOLAI博客</title><link rel="stylesheet" href="reset.css"><style>.main{display:table;}.main div{float:left;width:300px;height:300px;margin-right:20px;background:#966;}.footer{width:620px;height:100px;background:red;}</style></head><body><div class="wrap"><div class="main"><div>个人博客</div><div>个人网站</div></div><div class="footer"></div></div></body></html>
七:after 伪元素(不是伪类)
<!doctype html><html><head><meta charset="utf-8"><title>MAOLAI博客</title><link rel="stylesheet" href="reset.css"><style>.main div{float:left;width:300px;height:300px;margin-right:20px;background:#966;}.footer{width:620px;height:100px;background:red;}.clearfix:after{clear:both;display:block;height:0;content:"200B";}.clearfix{*zoom:1;}</style></head><body><div class="wrap"><div class="main clearfix"><div>个人博客</div><div>个人网站</div></div><div class="footer"></div></div></body></html>
注释:reset.css文件里面已经写好了after伪元素清浮动,
一:空标签清浮动(如下代码)
<!doctype html><html><head><meta charset="utf-8"><title>MAOLAI博客</title><link rel="stylesheet" href="reset.css"><style>.main div{float:left;width:300px;height:300px;margin-right:20px;background:#966;}.footer{width:620px;height:100px;background:red;}.clear{clear:both;height:0;}</style></head><body><div class="wrap"><div class="main"><div>个人博客</div><div>个人网站</div><p class="clear"></p></div><div class="footer"></div></div></body></html>
注释:上面用p标签进行空标签清浮动,
二:br标签清除浮动(如下代码)
<!doctype html><html><head><meta charset="utf-8"><title>MAOLAI博客</title><link rel="stylesheet" href="reset.css"><style>.main div{float:left;width:300px;height:300px;margin-right:20px;background:#966;}.footer{width:620px;height:100px;background:red;}</style></head><body><div class="wrap"><div class="main"><div>个人博客</div><div>个人网站</div><!--br标签自带的属性--><br clear="all"></div><div class="footer"></div></div></body></html>
三:父元素设置overflow:hidden (如下代码)
<!doctype html> <html> <head><meta charset="utf-8"> <title>MAOLAI博客</title> <link rel="stylesheet" href="reset.css"> <style> .main{overflow:hidden;} .main div{float:left;width:300px;height:300px;margin-right:20px;background:#966;} .footer{width:620px;height:100px;background:red;} </style> </head> <body> <div class="wrap"> <div class="main"> <div>个人博客</div> <div>个人网站</div> </div> <div class="footer"></div> </div> </body> </html>
四:父元素设置overflow:auto (如下代码)
<!doctype html><html><head><meta charset="utf-8"><title>MAOLAI博客</title><link rel="stylesheet" href="reset.css"><style>.main{overflow:auto;}.main div{float:left;width:300px;height:300px;margin-right:20px;background:#966;}.footer{width:620px;height:100px;background:red;}</style></head><body><div class="wrap"><div class="main"><div>个人博客</div><div>个人网站</div></div><div class="footer"></div></div></body></html>
五:父元素浮动
<!doctype html><html><head><meta charset="utf-8"><title>MAOLAI博客</title><link rel="stylesheet" href="reset.css"><style>.main{float:left;}.main div{float:left;width:300px;height:300px;margin-right:20px;background:#966;}.footer{width:620px;height:100px;background:red;}</style></head><body><div class="wrap"><div class="main"><div>个人博客</div><div>个人网站</div></div><div class="footer"></div></div></body></html>
效果:
注释:使得与父元素相邻的元素的布局会受到影响(影响到了类名为footer的元素)。
清除浮动有很多种,元素就没有浮动了,主要是帮助大家理解哪一种清除浮动比较好,所以叫清浮动。浮动会对文档产生影响,如何进行选择清电子爆分除浮动了?以下是清浮动的具体代码实现,南宫·NG体育当然可以用别的标签;如果用行元素的话需要进行转化为块,具体来看看会对文档产生什么影响?
清除浮动后的效果:
未清除浮动后的效果:
实例代码(未清除浮动):
<!doctype html><html><head><meta charset="utf-8"><title>MAOLAI博客</title><link rel="stylesheet" href="reset.css"><style>.main div{float:left;width:300px;height:300px;margin-right:20px;background:#966;}.footer{width:620px;height:100px;background:red;}</style></head><body><div class="wrap"><div class="main"><div>个人博客</div><div>个人网站</div></div><div class="footer"></div></div></body></html
解析:页面开发的时候可以为父级标签添加固定高度,块元素就没有必要转化啦。直接调用即可。但是有时希望内容能够撑开高度(比如内容不固定的时候)。
大家都知道,它们是能够撑开外部div的高度的,(不要误解成把浮动清除了,但是
Tags:
相关文章
5月30日,全新雷神Aura AI智能拍摄眼镜预约开启,颠覆你的摄影体验!
css如南宫·NG体育何清除电子爆分浮动clear与float标题:全新雷神Aura AI智能拍摄眼镜预约开启,颠覆你的摄影体验!随着科技的飞速发展,智能穿戴设备已经成为我们生活中不可或缺的一部分。雷神公司近日发布的Aura AI智能拍摄眼镜,更是以其独特的科技...
阅读更多
个人网站香港主机野草云选购
css如南宫·NG体育何清除电子爆分浮动clear与float许多新手建站时都会选择一些免费或便宜的主机来测试用,又因为建站备案等一系列繁琐步骤而选择国外或香港主机。网络上国外主机鱼龙混杂,众多香港虚拟主机服务商不稳定/甚至跑路,良莠不齐,而对于阿里云、腾讯云、...
阅读更多
wordpress响应式瀑布流博客主题snow
css如南宫·NG体育何清除电子爆分浮动clear与floatsnow是一款wordpress博客主题,布局使用了瀑布流的方式,文章三栏摆放。整个风格干净利落,并且支持自适性显示。支持置顶菜单。实在是一款不可多得的wordpress博客主题。snow适合建立流行...
阅读更多