2015-11-30 28 views
0

我遇到了問題!我在我的html中使用<picture>,我現在看到它在Safari和IE中不受支持。我有一個瀏覽器max-width: 660px的圖像和瀏覽器min-width: 660px的新圖像。有沒有人有關於如何做到這一點的建議?針對不同屏幕的不同圖片

+2

問題尋求幫助的代碼必須包括必要的重現它最短的代碼**在問題本身**。請參閱[**如何創建一個最小,完整和可驗證的示例**](http://stackoverflow.com/help/mcve) –

回答

0

img { 
 
    max-width: 100%; 
 
}
<picture> 
 
    <!-- Use CSS media queries in media attribute (this will show for screens less than 661px) --> 
 
    <source srcset="http://lorempixel.com/660/200" media="(max-width: 660px)"> 
 

 
    <!-- Default image (this will show for screens greater than 660px) --> 
 
    <source srcset="http://lorempixel.com/1200/400"> 
 

 
    <!-- Use this image if <picture> element isn't supported --> 
 
    <img src="http://lorempixel.com/1200/400" /> 
 
</picture>

+0

該代碼是我使用過的,但在Safari和IE中不支持。 – user5585207

+0

您可以使用[Picturefill](https://scottjehl.github.io/picturefill/)在舊版瀏覽器中添加'picture'支持。 –