我正在努力缩短我的CSS代码,以便设置背景图片的位置(居中)和大小(覆盖)。
每当我使用以下代码时,它显然可以正常工作:
HTML:
CSS(层叠样式表):
我想缩短/删除多个CSS重复的居中和覆盖属性(因为我有多个横幅ID,但具有重复的背景设置),但是以下代码无法正确地将图像居中并覆盖:
HTML:
CSS:
我做错了什么?
每当我使用以下代码时,它显然可以正常工作:
HTML:
<div class="banner-divider" id="banner-divider-welcome"></div>
<div class="banner-divider" id="banner-divider-second"></div>
CSS(层叠样式表):
.banner-divider{
width: 100%;
height:600px;
}
#banner-divider-welcome{
background: url(/images/welcome.jpg) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#banner-divider-second{
background: url(/images/second.jpg) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
我想缩短/删除多个CSS重复的居中和覆盖属性(因为我有多个横幅ID,但具有重复的背景设置),但是以下代码无法正确地将图像居中并覆盖:
HTML:
<div class="banner-divider" id="banner-divider-welcome"></div>
<div class="banner-divider" id="banner-divider-second"></div>
CSS:
.banner-divider{
width: 100%;
height:600px;
background: #fff;
background-image: none;
background-repeat: no-repeat
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#banner-divider-welcome{
background: url(/images/welcome.jpg);
}
#banner-divider-second{
background: url(/images/second.jpg);
}
我做错了什么?