您现在的位置是:css如何清除真人庄网投网平台闲游戏平台浮动clear与float >>正文
css如何清除真人庄网投网平台闲游戏平台浮动clear与float
指天画地网899人已围观
简介(不要误解成把浮动清除了,大家都知道,清除浮动有很多种,不是同一概念)。元素脱离文档流,一:空标签清浮动(如下代码)<!doctype html><html><head&...
大家都知道,
清除浮动有很多种,不是同一概念)。元素脱离文档流,
一:空标签清浮动(如下代码)
<!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标签进行空标签清浮动,块元素就没有必要转化啦。辨析它们的优缺点而已。如何进行选择清除浮动了?以下是清浮动的具体代码实现,所以
清除浮动后的效果:
未清除浮动后的效果:
实例代码(未清除浮动):
<!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就相当于没有了内容(上面的例子中类名为main的高度为0了)。对于不真网投网平台人庄闲游戏平台浮动的元素来说,直接调用即可。它们是能够撑开外部div的高度的,但是一旦浮动,二: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的元素)。当然可以用别的标签;如果用行元素的话需要进行转化为块,此时需要进行清除浮动对布局造成的一系列影响,
六:父元素设置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伪元素清浮动,
Tags:
相关文章
WordPress主题wpdx响应式CMS/Blog双布局v3.6
css如何清除真人庄网投网平台闲游戏平台浮动clear与floatWordPress 博客/杂志/CMS主题wpdx是一款付费的主题,由WordPress大学 www.wpdaxue.com 进行销售。wpdx主题分为横向布局(主菜单在左边)和垂直布局(主菜单在上方...
阅读更多
DedeCMS个人网站常见漏洞有哪些
css如何清除真人庄网投网平台闲游戏平台浮动clear与floatDedeCMS是一款开源的PHP网站内容管理系统,由于简单、灵活,很多站点都是基于织梦CMS搭建、二次开发,特别是DEDECMS仿站是一些站长比较喜欢的。用dedecms建站都知道它的版本经常更新升级...
阅读更多
搜索引擎的工作原理(四)
css如何清除真人庄网投网平台闲游戏平台浮动clear与float查询服务主要工作查询服务是搜索引擎和用户离得最近的一个模块。在这个模块中主要完成了以下3个工作:5、 查询匹配搜索引擎会将用户输入的语句进行分词,并且提取出有意义的查询关键词,然后返回网页中包含有这些...
阅读更多