背景图像示例
这是一个示例文本
以下是一个使用CSS来控制背景图像大小的示例:
HTML代码:
背景图像示例
这是一个示例文本
CSS代码 (styles.css):
body {
background-image: url("background.jpg");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
.content {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
上述代码中,我们将背景图像设置为background.jpg
,并使用CSS属性background-repeat: no-repeat
来阻止图像的重复显示。background-size: cover
属性设置背景图像自动调整大小以填充整个页面,background-position: center
属性将图像居中显示。
为了确保内容不被背景图像覆盖,我们将内容包裹在一个 这样,背景图像将只覆盖页面的可见部分,而不会覆盖整个页面。.content
并在CSS中给出相应的样式。
相关内容