css同級元素之間的清除浮動的技巧

來源:互聯網
上載者:User
清除左浮動:該元素的左邊不允許出現浮動元素而當前它的左邊有浮動元素,而自己本身又是塊元素,只能掉到下一行首開始顯示

clear: left;

清除右浮動:與上面相同,不允許元素的右邊出現浮動元素,同樣它只能在右浮動元素下面另起一行顯示,當然,它也只能沿著右浮動的最下面的底邊為起始點,開始顯示

clear: right;

如果該元素的左右二邊都禁止出現浮動元素,可以使用以下簡寫

clear:both;

<!DOCTYPE html><html><head><meta charset="UTF-8"><title>6.同級元素之間的清除浮動的技巧</title><style type="text/css">        .box1 {            width:200px;            height: 200px;            background-color: lightskyblue;            /*設定左浮動*/            float:left;        }        .box2 {            width:250px;            height: 250px;            background-color: lightgreen;/*設定右浮動*/            float:right;        }        .box3 {            width:300px;            height: 300px;            background-color: lightcoral; /*珊瑚色*/}</style></head><body><div></div><div></div><div></div></body></html>
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.