2013-07-27 63 views
0

再次,Internet Explorer耗費我的時間和金錢。Internet Explorer 7中圖像的最大寬度和最大高度

我正在做一個負責任的網站,我需要我的圖片是他們包含元素的不超過100%的寬度,也不會比情況下一定比例的高度就越脫落的頁面。

一些CSS:

#content{ 

    margin:0 auto; 
    min-width:320px; 
    max-width:800px; 
    width:80%; 
    background-color:green; 

} 

#featured{ 

    position:relative; 
    width:100%; 

} 

#featured-images{ 

    text-align:center; 

} 

#featured-images img{ 

    max-height:80%; 
    height:auto !important; /* IE fix */ 
    height:80%; /* IE fix */ 

    max-width:100%; 
    width:auto !important; /* IE fix */ 
    width:100%; /* IE fix * 

} 

一些標記:

<div id="content"> 
    <div id="featured"> 
    <div id="featured-images"> 
     <img src="lib/imgs/fi-1.jpg"/> 
    </div> 
    </div> 
</div> 

目前,此頁適用於Chrome。它甚至適用於IE6和IE8 +。我沒有在Firefox或Opera中測試過它。但IE 7絕對不會打球。它似乎將圖像縮小到很小的程度,就好像瀏覽器被重新調整爲一個殘片。

我知道這是不理想,但我一直在使用IE NetRenderer測試。

+0

您使用最小寬度不砍最大寬度黑客 – Hushme

+0

@Hushme你能不能解釋一下?或者提供替代方案? – shennan

+0

你正在使用100%爲什麼你需要最大寬度? – Hushme

回答

0

其固定,您可以點擊此處查看:

<style type="text/css"> 
#content { 
    margin:0 auto; 
    min-width:320px; 
    max-width:800px; 
    width:80%; 
    background-color:green; 
} 
#featured { 
    position:relative; 
    width:100%; 
} 
#featured-images { 
    text-align:center; 
} 
#featured-images img { 
    max-height:100%; 
    max-width:100%; 
    height:auto; 
    width:auto; 
} 
</style> 

<div id="content"> 
    <div id="featured"> 
     <div id="featured-images"> 
      <img src="https://www.google.co.in/images/srpr/logo4w.png" /> 
     </div> 
    </div> 
</div> 

或者撥弄這裏http://jsfiddle.net/Fqebe/1/

乾杯!

+0

並且怎麼樣'MAX-height'?我不希望圖片超過當前瀏覽器高度的80%... – shennan

+0

@shennan:當然,您可以將'max-height:100%;'更改爲'max-height:80%;'完全沒有問題。 –

+0

道歉,正在昏暗。這似乎已經成功了 - 儘管它已經把IE6搞砸了。但我現在對IE7的工作感到高興。我可以單獨攻擊IE6。出於興趣,爲什麼在'max-width'和'max-height'屬性之後堅持自動化似乎可以解決問題? – shennan

0

Internet Explorer的條件註釋樣式表...

http://www.jabcreations.com/web/css/ieccss

沒有JavaScript廠啓用。

無需破解,如果IE要求錯誤的價值觀,而不是你用什麼,然後(例如高/寬)只有IE瀏覽器的版本,則需要應用這些僞正確的價值觀,以將工作。

,可以讓你把所有的IE相關的污穢了你的主樣式表,你可以使用每個版本的IE特定IECCSS。

+0

我知道條件CSS,但我實際上只是試圖讓這個工作。一旦我知道什麼可行,什麼不可行,就會實現樣式表的純粹(ish)分離。 – shennan

相關問題