1 <div style="clear:both;"></div>
或者寫在br標籤裏面來解決,但這樣會增長無語義的標籤,下面是用after僞類實現,兼容多種瀏覽器
複製代碼
1 .clearfix:after{
2 content:"";
3 display:block;
4 height:0;
5 clear:both;
6 visibility:hidden;
7 }
複製代碼
爲兼容IE6,IE7,由於ie6,ie7不能用after僞類。加上下面代碼
1 .clearfix{zoom:1}
通常狀況下,若是父層內部有浮動(float)可能致使父層的高度爲0,加上clearfix後就好了
HTML:
1 <div class="parent clearfix">
2 <div class="left">left</div>
3 <div class="right">right</div>
4 </div>
CSS:
複製代碼
1 .clearfix{zoom:1}
2 .clearfix:after{
3 content:"";
4 display:block;
5 height:0;
6 clear:both;
7 visibility:hidden;
8 }
9 .parent{
10 background-color:red;
11 width:120px;
12 }
13 .left{
14 float:left;
15 background-color:pink;
16 height:60px;
17 }瀏覽器
<h3><a class="titlelnk" href="www.ytqczz.com/" target="_blank">煙臺汽車總站網上售票</a></h3>
18 .right{
19 float:right;
20 background-color:#abcdef;
21 }get