码迷,mamicode.com
首页 > 其他好文 > 详细

清除浮动之父级div定义伪类:after和zoom

时间:2019-10-14 14:30:05      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:doctype   class   order   hid   content   display   伪类   代码   方法   

这是比较常用的一种清除浮动的方法,各大网站都在采用:

<!Doctype html>
<html>
<head></head>
<body>
<style type="text/css"> 
   .div1{background:#333;border:1px solid red;}
   .div2{background:#888;border:1px solid red;height:100px;margin-top:10px}
   
   .left{float:left;width:20%;height:200px;background:#fff}
   .right{float:right;width:30%;height:80px;background:#fff}
   
   /*清除浮动代码*/
   .clearfloat:after{display:block;clear:both;content:"";visibility:hidden;height:0}
   .clearfloat{zoom:1}
   </style> 
<div class="div1 clearfloat"> 
<div class="left">Left</div> 
<div class="right">Right</div> 
</div>
<div class="div2">
   div2
   </div>
</body>
</html>

 

清除浮动之父级div定义伪类:after和zoom

标签:doctype   class   order   hid   content   display   伪类   代码   方法   

原文地址:https://www.cnblogs.com/xxySsm/p/11671042.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!