濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > HTML清除浮動(dòng)的其中兩種方式

HTML清除浮動(dòng)的其中兩種方式

熱門(mén)標(biāo)簽:重慶人工智能電銷(xiāo)機(jī)器人報(bào)價(jià) 強(qiáng)訊外呼系統(tǒng) 電話機(jī)器人批發(fā) 電銷(xiāo)外呼線路改不外呼線路 愛(ài)巢地圖標(biāo)注 長(zhǎng)春極信防封電銷(xiāo)卡公司 智能電銷(xiāo)機(jī)器人廣告語(yǔ) crm外呼系統(tǒng)好不好 貴陽(yáng)ai外呼系統(tǒng)

一、清除浮動(dòng)的方式一

給前面一個(gè)父元素設(shè)置高度,​注意:企業(yè)開(kāi)發(fā)中能不寫(xiě)高度就不寫(xiě)高度

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>D131_ClearFloat</title>
    <style>
        .smallbox1{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
            float:right;
​
        }
        .smallbox2{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .smallbox3{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .smallbox4{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .smallbox5{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .smallbox6{
            width:100px;
            height:100px;
            background-color: red;
            boder:3px solid black;
            margin:5px;
​
        }
        .bigbox1,.bigbox2{
            /*width:400px;*/
            /*width:400px;*/
            background-color: green;
            border:3px black solid;
        }
</style>
</head>
<body>
<div class="bigbox1">
    <div class="smallbox1"></div>
    <div class="smallbox2"></div>
    <div class="smallbox3"></div>
</div>
<div class="bigbox2">
    <div class="smallbox4"></div>
    <div class="smallbox5"></div>
    <div class="smallbox6"></div>
</div>
</body>
</html>

二、清除浮動(dòng)的第二種方式

給后面的屬性添加clear屬性

clear屬性取值:

none:默認(rèn)取值,按照浮動(dòng)元素的排序規(guī)則進(jìn)行排序(左浮動(dòng)找左浮動(dòng),右浮動(dòng)找右浮動(dòng))

left:不要找前面的左浮動(dòng)元素

right:不要找前面的右浮動(dòng)元素

both:不要找前面的左浮動(dòng)和有浮動(dòng)元素

例如:我們不設(shè)置大盒子的寬高,小盒子會(huì)把大盒子撐起來(lái),但是兩個(gè)大盒子會(huì)因此而在一行上

 .smallbox1{
            width:100px;
            height: 100px;
            float:left;
            background-color: red;
            border:2px solid black;
        }
        .smallbox2{
            width:100px;
            height: 100px;
            float:left;
            background-color: red;
            border:2px solid black;
        }
        .smallbox3{
            width:100px;
            height: 100px;
            float:left;
            background-color:blue;
            border:2px solid black;
        }
        .smallbox4{
            width:100px;
            height: 100px;
            float:left;
            background-color: blue;
            border:2px solid black;
        }
    </style>
</head>
<body>
<div class="bigbox1">
    <div class="smallbox1"></div>
    <div class="smallbox2"></div>
</div>
<div class="bigbox2">
    <div class="smallbox3"></div>
    <div class="smallbox4"></div>
</div>
</body>

我們使用clear屬性在第三個(gè)小盒子上,這樣就可以另起一行了(第四個(gè)就不用,因?yàn)槲覀兙拖胱尩谌齻€(gè)挨著第四個(gè)),只需要第三個(gè)小盒子的代碼修改代碼

      .smallbox3{
            clear:left;
            width:100px;
            height: 100px;
            float:left;
            background-color:blue;
            border:2px solid black;
        }

​注意點(diǎn):margin屬性失效了,不失效的方式我們下次再說(shuō)。

三、源碼:

D131_ClearFloat.html

D132_CLearAttribute.html

地址:

https://github.com/ruigege66/HTML_learning/blob/master/D131_ClearFloat.html

https://github.com/ruigege66/HTML_learning/blob/master/D132_CLearAttribute.html

總結(jié)

以上所述是小編給大家介紹的HTML清除浮動(dòng)的其中兩種方式,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

標(biāo)簽:清遠(yuǎn) 陜西 吳忠 山南 內(nèi)蒙古 上海 保定 廣安

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML清除浮動(dòng)的其中兩種方式》,本文關(guān)鍵詞  HTML,清除,浮動(dòng),的,其中,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《HTML清除浮動(dòng)的其中兩種方式》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于HTML清除浮動(dòng)的其中兩種方式的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    定西市| 自贡市| 宾阳县| 千阳县| 合山市| 华宁县| 雷波县| 姜堰市| 蓝田县| 寿光市| 景泰县| 金坛市| 岳阳县| 天气| 白玉县| 葵青区| 松滋市| 凤山市| 沾益县| 章丘市| 肇庆市| 景德镇市| 寿阳县| 崇义县| 广州市| 孟连| 习水县| 合川市| 镇江市| 左权县| 中江县| 筠连县| 海宁市| 盘山县| 芒康县| 新巴尔虎右旗| 准格尔旗| 司法| 罗定市| 延长县| 抚松县|