清除浮動

CSS樣式中有浮動的狀況下,通常都不但願正常的文檔流顯示的內容被蓋住,因此有浮動的狀況下,會緊跟着後面加一個div清除浮動。css

.clear{
            width: 0px;
            height: 0px;
            clear:both;
        }

  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>清除浮動</title>
    <style type="text/css">
        .div1{
            width: 200px;
            height: 200px;
            background-color: green;
            float: left;
        }
        .div2{
            width: 200px;
            height: 200px;
            background-color: red;
            float: left;
        }
        .div3{
            width: 500px;
            height: 500px;
            background-color: gray;
        }
        .clear{
            width: 0px;
            height: 0px;
            clear:both;
        }
    </style>
</head>
<body>
    <div class="div1"></div>
    <div class="div2"></div>
    <div class="clear"></div>
    <div class="div3"></div>
</body>
</html>
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息