我目前正在完成一项学校练习任务,但不知道如何在容器后添加背景图像。这是我快速找到的一个示例,注意背景图像:http://www.njuskalo.hr。我尝试将背景图像添加到body中,但也没有效果。我还创建了两个新的div标签(.left和.right)来尝试将其添加到容器的两侧,但也无效。以下是我的代码:http://textuploader.com/d5j5d。请注意,我更改和删除了许多内容以尝试其他方法。请原谅我的代码很混乱,因为我是临时完成的,所以请指出所有错误。
.container {
background-image: url("../images/backgroundImageLocation.jpg");
}
body{
background-image: url("http://image.flaticon.com/teams/1-freepik.jpg");
background-repeat: repeat;
background-size: 50px;
}
.container {
position: relative;
margin-left: auto;
margin-right: auto;
margin-top: 100px;
width: 200px;
height: 200px;
background-color: pink;
}
.left {
position: absolute;
left: -100px;
width: 100px;
height: 200px;
background-color: red;
}
.right {
position: absolute;
right: -100px;
width: 100px;
height: 200px;
background-color: green;
}
<div class="container">
<div class="left"></div>
<div class="right"></div>
</div>
可以与背景一起使用:
body, html {
background: url("../YOUR_IMAGE_PATH/image.jpg") no-repeat fixed center center;
}
no-repeat 不会重复背景,fixed 在滚动时将固定背景,center center 将图像居中到页面。
使用background-image属性:
body, html {
background-image: url("../YOUR_IMAGE_PATH/image.jpg")
}