響應式設計中的響應式圖片製做

兩種方法實現響應式圖片:css

  1. <picture>
  2. <img>

在該兩個標籤中使用srcsetsizes屬性,如:git

<article>
    <img  src="small.png"
          srcset="large.png 1280w, medium.png 640w, small.png 320w"
          sizes="(man-width:500px) 700x, 100vm" 
          alt="Alternate text" />
</article>

配合的css以下github

article{
    margin: 0 auto;
    max-width: 700px; 
}
@media (max-width: 500px) {
  img {width: 250px }
}

<picture>
   <source media="(min-width: 36em)"
           srcset="large.jpg  1024w,
                   medium.jpg 640w,
                   small.jpg  320w"
           sizes="33.3vw" />
   <source srcset="cropped-large.jpg 2x,
                   cropped-small.jpg 1x" />
   <img src="small.jpg" alt="A rad wolf" />
</picture>

轉載摘抄翻譯自: ide

  • http://css-tricks.com/video-screencasts/133-figuring-responsive-images/?utm_source=dlvr.it&utm_medium=twitter
  • http://scottjehl.github.io/picturefill/
  • http://martinwolf.org/2014/05/07/the-new-srcset-and-sizes-explained/
  • http://ericportis.com/posts/2014/srcset-sizes/
相關文章
相關標籤/搜索