背景大小 | background-size (Backgrounds & Borders) - CSS 中文开发手册 - Break易站
CSS 中文开发手册
背景大小 | background-size (Backgrounds & Borders) - CSS 中文开发手册
background-size CSS属性指定一个元素的背景图像的大小。图像可以保留其自然大小,拉伸到一个新的大小,或约束,以适应可用空间,同时保持其固有的比例。
/* Keyword values */ background-size: cover; background-size: contain; /* One-value syntax */ /* the width of the image (height becomes 'auto') */ background-size: 50%; background-size: 3.2em; background-size: 12px; background-size: auto; /* Two-value syntax */ /* first value: width of the image, second value: height */ background-size: 50% auto; background-size: 3em 25%; background-size: auto 6px; background-size: auto auto; /* Multiple backgrounds */ background-size: auto, auto; /* Not to be confused with `auto auto` */ background-size: 50%, 25%, 25%; background-size: 6px, auto, contain; /* Global values */ background-size: inherit; background-size: initial; background-size: unset;