我希望在新网站的首页上放置一张图片,以覆盖整个宽度,并根据您的分辨率更改尺寸,但仍然将其水平居中。
这是我目前正在处理的网站:http://jonathan.ohrstrom.nu,我希望此图片覆盖整个红色部分:http://jonathan.ohrstrom.nu/style/img/featured.jpg
我该怎么做?这是我想要图像的div的css代码:
.featured {
background-color: red;
width: 100%;
height: 700px;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
我试过这个没有成功:
.featured {
background-image: url(http://jonathan.ohrstrom.nu/style/img/featured.jpg) no-repeat;
width: 100%;
height: 700px;
size: cover;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
但是根本没有加载图像。没有no-repeat
,那么图像覆盖了整个宽度,但它重复了自己..
答案 0 :(得分:0)
以下是我的建议:
.featured {
background-image: url(http://jonathan.ohrstrom.nu/style/img/featured.jpg);
background-repeat: no-repeat;
background-size: cover;
background-position: center center;
width: 100%;
height: 700px;
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
您可以使用CSS后台属性做很多事情: