IE6相容inline-block的方法,ie6相容inline-block

來源:互聯網
上載者:User

IE6相容inline-block的方法,ie6相容inline-block

或許有朋友會對IE不支援 display:inline-block 屬性,表示疑問或者反對。說:“我在 IE 中對 a 或者 span 等內嵌元素使用 display:inline-block 一直是有效”。

其實不然,在IE中對內嵌元素使用 display:inline-block,IE 是不識別的,但使用 display:inline-block 在 IE 下會觸發 layout, 從而使內嵌元素擁有了display:inline-block 屬性的表症。從上面的這個分析,也不難理解為什麼 IE 下,對塊元素設定 display:inline-block 屬性無法實現 inline-block 的效果。這時塊元素僅僅是被 display:inline-block 觸發了 layout,而它本就是行布局,所以觸發後,塊元素依然還是行布局,而不會如 Opera 中塊元素呈遞為內聯對象。

IE下塊元素如何? display:inline-block 的效果?

有兩種方法:

1、先使用 display:inline-block 屬性觸發塊元素,然後再定義 display:inline,讓塊元素呈遞為內聯對象(兩個display 要先後放在兩個 CSS 聲明中才有效果,這是 IE 的一個經典 bug ,如果先定義了 display:inline-block,然後再將 display 設回 inline 或 block,layout 不會消失)。代碼如下(…為省略的其他屬性內容):

div {display:inline-block;...}
    div {display:inline;}

2、直接讓塊元素設定為內聯對象呈遞(設定屬性 display:inline),然後觸發塊元素的 layout(如:zoom:1 等)。代碼如下:

div {display:inline; zoom:1;...}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.