W3C Validation of SRCSET

前端 未结 2 348
长发绾君心
长发绾君心 2021-01-22 00:59

W3C Validator is throwing an error on the following code:

\"My

        
2条回答
  •  悲&欢浪女
    2021-01-22 01:29

    This answers only for your update: The reason for this is, that the browser chooses one candidate from your srcset, the src attribute is used as a fallback. This means to get the larger candidate you need to also add it to your srcset:

    
    

    I don't really know your image layout, but I doubt, that sizes is correct here. If this image is displayed fullwidth until 1420px your sizes attribute should look like this.

    sizes="(min-width: 1420px) 1420px, 100vw"

    or

    sizes="(max-width: 1420px) 100vw, 1420px"

    Additionally you should use more images. Note if you use the width descriptor the browser automatically handles the density for you (for retina devices). Use at least 640w, 980w/1024w, 1420w, 2048w.

提交回复
热议问题