自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

IE CSS Bug系列:不正確的浮動伸縮Bug

開發(fā) 前端
IE 瀏覽器不支持很多 CSS 屬性是出了名的,即便在支持的部分中,也是有很多 Bug 的。Zoffix Znet 整理了 IE 中的 CSS 問題,有簡單的問題示例,也有解決方法。 這個系列共有 58 個指南,70 個解決方案。

影響的IE版本

這個 bug 影響 IE7、IE6

表現(xiàn)

跟隨在其他浮動元素之后的浮動元素,設置clear屬性時不能正確伸縮

教程編寫時間

2009.8.18 21:17:12

描述

這是我在 Gérard Talbot 收集整理的 IE7 Bug 頁面發(fā)現(xiàn)的bug之一(我大部分案例都是從那來的)。這個bug影響IE7跟IE6,表現(xiàn)就是設置了 clear 屬性的浮動元素并不能正確地伸縮。我們來看一下:

演示

示例在這個獨立頁面

HTML代碼:

  1. <div> 
  2.     Here is a &lt;div&gt; having float: left and clear: left. As expected, 
  3.     it takes, it occupies as much width it requires from the body's content 
  4.     area. 
  5. </div> 
  6.   
  7. <div> 
  8.     This is the same type of &lt;div&gt;: a left-floated &lt;div&gt; with 
  9.     clear: left. This &lt;div&gt; should use, should take, should occupy 
  10.     the whole content area of the body node (expected results). However, in 
  11.     Internet Explorer 7, this left-floated &lt;div&gt; with clear: left only 
  12.     takes, only occupies a very narrow chunk of the body's content area 
  13.     (actual results). More text filling. More text filling. More text 
  14.     filling. More text filling. More text filling. 
  15. </div> 
  16.   
  17. <div> 
  18.     Here, a third &lt;div&gt; having float: left and clear: left. Change 
  19.     your browser window viewport's width. 
  20. </div> 
  21.   
  22. <ul> 
  23.     <li> 
  24.     Here is a &lt;div&gt; having float: left and clear: left. As expected, 
  25.     it takes, it occupies as much width it requires from the body's content 
  26.     area. 
  27.     </li> 
  28.   
  29.     <li> 
  30.         This is the same type of &lt;div&gt;: a left-floated &lt;div&gt; with 
  31.         clear: left. This &lt;div&gt; should use, should take, should occupy 
  32.         the whole content area of the body node (expected results). However, in 
  33.         Internet Explorer 7, this left-floated &lt;div&gt; with clear: left only 
  34.         takes, only occupies a very narrow chunk of the body's content area 
  35.         (actual results). More text filling. More text filling. More text 
  36.         filling. More text filling. More text filling. 
  37.     </li> 
  38.   
  39.     <li> 
  40.         Here, a third &lt;div&gt; having float: left and clear: left. Change 
  41.         your browser window viewport's width. 
  42.     </li> 
  43. </ul> 

CSS 代碼:

  1. div, li { 
  2.     background-color#ddd
  3.     border1px solid green
  4.     clearleft
  5.     colorblack
  6.     floatleft

在IE6跟IE7中可以發(fā)現(xiàn)第二、第三個<li>及<div>不能正確地伸縮。它們被“截”短了,過早伸縮了。據(jù)Sjaak Prieste所說(Gérard Talbot在這個bug中稱贊了他),原因是這樣的,IE首先把該浮動元素與上一個浮動元素渲染在同一行中,然后發(fā)現(xiàn)’clear’屬性,清除浮動將其移到下一行,但沒有重新排布文本。

我的演示中既有<div>也有<li>的原因是,這兩種情況的處理方法有點區(qū)別。在“解決方案”中會有更多說明。

解決方案

以下是上述bug的解決方法(以類型排序)

解決方法(對清除進行標記)

該方法的時間

Tue Aug 18 21:17:26 2009

可修復的的版本

所有受該bug影響的版本

描述

我找不到一個像樣的辦法,如果誰有比較好的、相對簡潔的辦法,請評論給我!下面是我的方法:

修復bug的演示在這個獨立頁面

HTML Code:

  1. <div> 
  2.     Here is a &lt;div&gt; having float: left and clear: left. As expected, 
  3.     it takes, it occupies as much width it requires from the body's content 
  4.     area. 
  5. </div> 
  6. <span class="ie_fix"></span> 
  7. <div> 
  8.     This is the same type of &lt;div&gt;: a left-floated &lt;div&gt; with 
  9.     clear: left. This &lt;div&gt; should use, should take, should occupy 
  10.     the whole content area of the body node (expected results). However, in 
  11.     Internet Explorer 7, this left-floated &lt;div&gt; with clear: left only 
  12.     takes, only occupies a very narrow chunk of the body's content area 
  13.     (actual results). More text filling. More text filling. More text 
  14.     filling. More text filling. More text filling. 
  15. </div> 
  16. <span class="ie_fix"></span> 
  17. <div> 
  18.     Here, a third &lt;div&gt; having float: left and clear: left. Change 
  19.     your browser window viewport's width. 
  20. </div> 
  21.   
  22. <ul> 
  23.     <li> 
  24.         <div>Here is a &lt;div&gt; having float: left and clear: left. As expected, 
  25.         it takes, it occupies as much width it requires from the body's content 
  26.         area.</div> 
  27.     </li> 
  28.   
  29.     <li> 
  30.         <div>This is the same type of &lt;div&gt;: a left-floated &lt;div&gt; with 
  31.         clear: left. This &lt;div&gt; should use, should take, should occupy 
  32.         the whole content area of the body node (expected results). However, in 
  33.         Internet Explorer 7, this left-floated &lt;div&gt; with clear: left only 
  34.         takes, only occupies a very narrow chunk of the body's content area 
  35.         (actual results). More text filling. More text filling. More text 
  36.         filling. More text filling. More text filling.</div> 
  37.     </li> 
  38.   
  39.     <li> 
  40.         <div>Here, a third &lt;div&gt; having float: left and clear: left. Change 
  41.         your browser window viewport's width.</div> 
  42.     </li> 
  43. </ul> 

CSS Code:

  1. div { 
  2.     background-color#ddd
  3.     border1px solid green
  4.     clearleft
  5.     colorblack
  6.     floatleft
  7. .ie_fix { display: inline-block; } 
  8. .ie_fix { displayblock; } 

看下這邊我做的事。在示例中的div部分,我在各div之間插入一個額外的<span>元素,并且通過 {display: inline-block;}給它一個”布局”(layout),然后設置其display屬性為block。

因為<li>元素之間插入<span>元素不大合適,在示例的<ul>部分我將每個<li>的內容用一個<div>包起來,然后將那個div設為浮動(注意這邊將 li 的浮動刪掉了)。

在正常的瀏覽器里,最初的示例中浮動元素的伸縮可以完全適應其包圍元素的變化,而我們的修復版本并不能做到。因而這個解決方法并不完美,不過也許可以幫助到你。

原文鏈接:http://haslayout.net/css/Incorrect-Float-Shrink-Wrap-Bug

譯文鏈接:http://blog.jobbole.com/47426/

責任編輯:陳四芳 來源: 伯樂在線
相關推薦

2013-10-30 09:57:43

IECSS

2013-10-31 11:12:56

IECSS

2013-10-28 14:01:03

IECSS

2013-10-31 10:59:23

IECSS

2024-09-09 09:32:18

2013-10-29 15:20:38

IECSS

2013-10-29 10:32:59

IECSS

2009-08-13 10:12:07

IE的CSS Bug

2010-09-03 09:55:10

CSS偽類hover

2010-08-17 15:38:49

CSS兼容IE7IE8

2023-03-16 23:54:19

服務器vmtoolsd組件

2018-04-09 09:04:59

固態(tài)硬盤映射表

2015-06-29 09:44:55

2012-10-15 18:19:25

打印機打印機安裝

2011-07-29 16:55:44

Java 7

2009-03-28 09:50:02

IE8微軟瀏覽器

2010-08-18 09:55:38

IE6

2014-11-14 14:03:17

微軟安全漏洞bug

2023-11-15 17:23:30

測試軟件開發(fā)

2011-08-17 13:18:39

Oracle 10g配SID
點贊
收藏

51CTO技術棧公眾號