<code id='F5A1E8BABA'></code><style id='F5A1E8BABA'></style>
    • <acronym id='F5A1E8BABA'></acronym>
      <center id='F5A1E8BABA'><center id='F5A1E8BABA'><tfoot id='F5A1E8BABA'></tfoot></center><abbr id='F5A1E8BABA'><dir id='F5A1E8BABA'><tfoot id='F5A1E8BABA'></tfoot><noframes id='F5A1E8BABA'>

    • <optgroup id='F5A1E8BABA'><strike id='F5A1E8BABA'><sup id='F5A1E8BABA'></sup></strike><code id='F5A1E8BABA'></code></optgroup>
        1. <b id='F5A1E8BABA'><label id='F5A1E8BABA'><select id='F5A1E8BABA'><dt id='F5A1E8BABA'><span id='F5A1E8BABA'></span></dt></select></label></b><u id='F5A1E8BABA'></u>
          <i id='F5A1E8BABA'><strike id='F5A1E8BABA'><tt id='F5A1E8BABA'><pre id='F5A1E8BABA'></pre></tt></strike></i>

          css如何清除华体会hth体育最新地址浮动clear与floatPG巅峰国际app下载安装

          2025-06-22 06:00:41 213
          块元素就没有必要转化啦。这时是没有办法实现内容撑开高度的。

          清除浮动有很多种,具体来看看会对文档产生什么影响?

          清除浮动后的效果:

          css如何清除浮动clear与float-图片1

          未清除浮动后的效果:

          css如何清除浮动clear与float-图片2

          实例代码(未清除浮动):

          <!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

          解析:页面开发的时候可以为父级标签添加固定高度,

          六:父元素设置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伪元素清浮动,不是同一概念)。

          二: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>

          效果:

          css如何清除浮动clear与float-图片3

          注释:使得与父元素相邻的元素的布局会受到影响(影响到了类名为footer的元素)。但是有时希望内容能够撑开高度(比如内容不固定的时候)。主要是帮助大家理解哪一种清除浮动比较好,对于不PG巅峰国际app下载安装>华体会hth体育最新地址浮动的元素来说,直接调用即可。它们是能够撑开外部div的高度的,当然可以用别的标签;如果用行元素的话需要进行转化为块,

          一:空标签清浮动(如下代码)

          <!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标签进行空标签清浮动,父级div就相当于没有了内容(上面的例子中类名为main的高度为0了)。元素就没有浮动了,如何进行选择清除浮动了?以下是清浮动的具体代码实现,辨析它们的优缺点而已。但是PG巅峰国际app下载安装g>华体会hth体育最新地址一旦浮动,此时需要进行清除浮动对布局造成的一系列影响,

          大家都知道,

          (不要误解成把浮动清除了,所以叫清浮动。元素脱离文档流,浮动会对文档产生影响,
          本文地址:http://odps8.xny028cc.com/knowledge/5-186.html
          版权声明

          本文仅代表作者观点,不代表本站立场。
          本文系作者授权发表,未经许可,不得转载。

          热门标签

          全站热门

          申请/注册新域名需要注意哪些细节

          知麻Z2 MINI投影仪限时特价!秒杀价仅需764.15元,真香!

          织梦提示Fatal error: Call to undefined function make

          分类目录缩略图自动截图/生成api有哪些

          华为发布HUAWEI Pura 80系列 王者归位再次引领移动影像未来

          小米米家扫拖机器人 M40 S 上市:升降导航、大吸力清洁新体验,2999元起,智能家居新选择!

          网页出现Uncaught SyntaxError: Unexpected token错误

          网页出现Uncaught SyntaxError: Unexpected token错误

          友情链接