css overflow:hidden 清除浮动

来源:互联网 发布:matlab编程第二版答案 编辑:程序博客网 时间:2024/05/17 07:32

发现overflow:hidden 有clear:both 的功效



当父容器设置了 overflow:hidden 的时候

发现效果 等效于设置了父容器的清除浮动伪类  :after  clear:both





<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="gbk">
    <style type="text/css">
        .wyFirst {
            width: 100px;
            height: 100px;
            background-color: red;
            float: left;


        }


        .wySecond {


            width: 100px;
            height: 100px;
            background-color: blue;
            float: left;


        }


        .wrapper {


            background-color: yellow;

overflow:hidden;// 这一句与下面after 等效
        }


        .wrapper:after {
            clear: both;
            display: block;
            content: " ";
        }


        .wyThird {


            width: 100px;
            height: 100px;
            background-color: green;


            float: left;


        }
    </style>
</head>
<body>
<div>
    <div class="wrapper">
        <div class="wyFirst">this is a test</div>
        <div class="wySecond">this is a float</div>
    </div>
    <div class="wyThird">this is a float</div>
</div>
</body>
</html>

0 0