Specifying multiple slot widths


目录

View the code

<img src="flower.jpg"
  srcset="flower-small.jpg 480w, flower-large.jpg 800w"
  sizes="(max-width: 480px) 100vw, (max-width: 1024px) 50vw, 800px">

What's going on here?

The value of the sizes attribute dictates that image display width will be: "100% of the viewport width" on viewports up to 480px wide, "50% of the viewport width" on screens 481–1024px wide, and 800px on screens wider than 1024px. These widths match the widths specified in the CSS.

The ability to specify multiple slot widths accommodates page layouts that use different styling (that is, image widths) for different viewport sizes.

How to specify multiple slot widths

The following is not a valid width:


版本号 #3
由 壳壳虫 创建于 2026-10-31 22:34:19 UTC
由 cocobook-sync 更新于 2026-11-04 17:38:46 UTC