您好,欢迎访问宜昌市隼壹珍商贸有限公司
400 890 5375background-size用于控制背景图尺寸,取值包括auto、具体数值、百分比、cover和contain,配合background-position和background-repeat可实现全屏背景、图标缩放等效果。
在CSS中,background-size 属性用于控制背景图像的尺寸,从而实现对背景图的缩放效果。通过设置不同的值,可以灵活地调整背景图的显示大小,适应容器区域。
如 50% 75%):相对于父容器的尺寸进行缩放。例如,50% 宽表示背景图宽度为容器宽度的一半。center。no-repeat。例如,创建一个全屏背景图常见写法:
div {
background-image: url('bg.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
width: 100%;
height: 100vh;
}
基本上就这些。合理使用 background-size 能有效控制背景图缩放行为,提升页面视觉表现。