我怎样才能在背景前面但在另一个背景后面添加一个 before 伪元素?
How can i bring a before pseudo element in front of a Background but behind of an other background?
我使用多个背景。我在带有 Css3 代码和背景图像的多背景后面使用了一个 before Element。
我还有一个名为 (apc-container) 的背景。
我的问题是前元素也在#acp-container 后面。
在我使用 z-index 之前的伪元素中。
我也尝试在 #acp-container 中使用它,但它不起作用。
那么我如何将 before 伪元素放在#apc-container 前面和#subfilter 后面的 BG 中?
你可以用这段代码检查一下,你很容易发现问题。
#streams-container,
#acp-container {
border-radius: 10px;
background-color: #f8f8f8;
min-height: 500px;
}
.subfilter {
margin-top: 160px;
}
.subfilter a {
margin-right: 130px;
margin-left: 130px;
width: 145px;
height: 145px;
display: inline-block;
position: relative;
line-height: 145px;
background-size: auto auto, auto auto;
background-color: #eaeaea;
background-image: url(images/Eye.png), -webkit-gradient(linear, left top, left bottom, from(#f6f6f6), to(#eaeaea));
background-image: url(images/Eye.png), -webkit-linear-gradient(top, #f6f6f6, #eaeaea);
background-image: url(images/Eye.png), -moz-linear-gradient(top, #f6f6f6, #eaeaea);
background-image: url(images/Eye.png), -ms-linear-gradient(top, #f6f6f6, #eaeaea);
background-image: url(images/Eye.png), -o-linear-gradient(top, #f6f6f6, #eaeaea);
background-image: url(images/Eye.png), linear-gradient(top, #f6f6f6, #eaeaea);
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, .25), 0 2px 3px rgba(0, 0, 0, .1);
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .25), 0 2px 3px rgba(0, 0, 0, .1);
box-shadow: 0 1px 1px rgba(0, 0, 0, .25), 0 2px 3px rgba(0, 0, 0, .1);
}
.subfilter a.finiwatch {
background-position: 0px -172px, 0 0;
}
.subfilter a:active {
top: 1px;
}
.subfilter a::before {
content: '';
position: absolute;
z-index: -1;
top: -8px;
right: -8px;
bottom: -8px;
left: -8px;
background-color: #eaeaea;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
opacity: 0.5;
}
.subfilter a:active::before {
top: -9px;
}
.subfilter a:hover::before {
opacity: 1;
}
.subfilter a.finiwatch:hover::before {
background-color: #B3F390;
}
.subfilter a:hover {
top: 0px, 1px;
}
.subfilter a.finiwatch:hover {
background-position: -160px -158px, 0 0;
}
.subfilter a:active {
background: url(images/Eye.png), -moz-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), -webkit-gradient(linear, left top, left bottom, from(#eaeaea), to(#f6f6f6));
background-image: url(images/Eye.png), -webkit-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), -moz-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), -ms-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), -o-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), linear-gradient(top, #eaeaea, #f6f6f6);
}
.subfilter a.finiwatch:active {
background-position: -318px -158px, 0 0;
}
.subfilter a.finiwatch:selected {
background-position: -318px -158px, 0 0;
}
<div id="streams-container">
<div class="subfilter">
<a class="finiwatch" href=""></a>
</div>
找到方法了
给 apc-container 一个相对位置和一个 1 的 z-index 和 teh before element 一个 -10 的 z-index。
#streams-container,
#acp-container {
border-radius: 10px;
background-color: #f8f8f8;
min-height: 500px;
position: relative;
z-index: 1;
}
.subfilter a::before {
content: '';
position: absolute;
z-index: -10;
top: -8px;
right: -8px;
bottom: -8px;
left: -8px;
background-color: #eaeaea;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
opacity: 0.5;
}
我使用多个背景。我在带有 Css3 代码和背景图像的多背景后面使用了一个 before Element。 我还有一个名为 (apc-container) 的背景。
我的问题是前元素也在#acp-container 后面。 在我使用 z-index 之前的伪元素中。 我也尝试在 #acp-container 中使用它,但它不起作用。
那么我如何将 before 伪元素放在#apc-container 前面和#subfilter 后面的 BG 中?
你可以用这段代码检查一下,你很容易发现问题。
#streams-container,
#acp-container {
border-radius: 10px;
background-color: #f8f8f8;
min-height: 500px;
}
.subfilter {
margin-top: 160px;
}
.subfilter a {
margin-right: 130px;
margin-left: 130px;
width: 145px;
height: 145px;
display: inline-block;
position: relative;
line-height: 145px;
background-size: auto auto, auto auto;
background-color: #eaeaea;
background-image: url(images/Eye.png), -webkit-gradient(linear, left top, left bottom, from(#f6f6f6), to(#eaeaea));
background-image: url(images/Eye.png), -webkit-linear-gradient(top, #f6f6f6, #eaeaea);
background-image: url(images/Eye.png), -moz-linear-gradient(top, #f6f6f6, #eaeaea);
background-image: url(images/Eye.png), -ms-linear-gradient(top, #f6f6f6, #eaeaea);
background-image: url(images/Eye.png), -o-linear-gradient(top, #f6f6f6, #eaeaea);
background-image: url(images/Eye.png), linear-gradient(top, #f6f6f6, #eaeaea);
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
-moz-box-shadow: 0 1px 1px rgba(0, 0, 0, .25), 0 2px 3px rgba(0, 0, 0, .1);
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, .25), 0 2px 3px rgba(0, 0, 0, .1);
box-shadow: 0 1px 1px rgba(0, 0, 0, .25), 0 2px 3px rgba(0, 0, 0, .1);
}
.subfilter a.finiwatch {
background-position: 0px -172px, 0 0;
}
.subfilter a:active {
top: 1px;
}
.subfilter a::before {
content: '';
position: absolute;
z-index: -1;
top: -8px;
right: -8px;
bottom: -8px;
left: -8px;
background-color: #eaeaea;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
opacity: 0.5;
}
.subfilter a:active::before {
top: -9px;
}
.subfilter a:hover::before {
opacity: 1;
}
.subfilter a.finiwatch:hover::before {
background-color: #B3F390;
}
.subfilter a:hover {
top: 0px, 1px;
}
.subfilter a.finiwatch:hover {
background-position: -160px -158px, 0 0;
}
.subfilter a:active {
background: url(images/Eye.png), -moz-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), -webkit-gradient(linear, left top, left bottom, from(#eaeaea), to(#f6f6f6));
background-image: url(images/Eye.png), -webkit-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), -moz-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), -ms-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), -o-linear-gradient(top, #eaeaea, #f6f6f6);
background-image: url(images/Eye.png), linear-gradient(top, #eaeaea, #f6f6f6);
}
.subfilter a.finiwatch:active {
background-position: -318px -158px, 0 0;
}
.subfilter a.finiwatch:selected {
background-position: -318px -158px, 0 0;
}
<div id="streams-container">
<div class="subfilter">
<a class="finiwatch" href=""></a>
</div>
找到方法了
给 apc-container 一个相对位置和一个 1 的 z-index 和 teh before element 一个 -10 的 z-index。
#streams-container,
#acp-container {
border-radius: 10px;
background-color: #f8f8f8;
min-height: 500px;
position: relative;
z-index: 1;
}
.subfilter a::before {
content: '';
position: absolute;
z-index: -10;
top: -8px;
right: -8px;
bottom: -8px;
left: -8px;
background-color: #eaeaea;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
opacity: 0.5;
}