只是为个人项目编写一点代码,出于某种原因,背景图像一直与我的标题和其他 div 重叠。放入一个虚拟标题以显示,但图像显然应该包含在 div 中,我似乎无法正确理解!非常感谢有关如何将其包含在其中的任何建议。
另外,在旁注中,我希望第一张图像显示 before 悬停,但现在包含图像更令人沮丧。我已经使用下面的方法使图像适合,所以也许与此有关?
background-repeat:no-repeat;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
background-position:center;
答案 0 :(得分:0)
将“z-index”添加到您的 CSS。这是一种定义哪个 div 位于另一个 div 之上的方法。
答案 1 :(得分:0)
伙计,你必须做的是:
.container{
position: relative;
}
.bg:before {
position:absolute;
content:"";
z-index:1;
width: 50%;
height: 100%;
top:0px;
right: 0;
transition:1s all;
opacity:0;
background-repeat:no-repeat;
-webkit-background-size:cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size:cover;
background-position:center;
}
.bg1:before{opacity:1;} /*to make the first image display at first*/