如何清除CSS中父元素放置的过滤器?

时间:2017-08-09 17:22:01

标签: html css css-filters

我有一张带有背景图片的<div>,我希望背景图片能够应用滤镜。但我也希望div包含覆盖图像的<p>标记 - 我不希望<p>拥有相同的过滤器。

如何清除<div><p>设置的过滤器?

到目前为止我得到了什么:

<div className="artistDetailImage" style={{backgroundImage: url(${this.props.artistImage})`}}>
  <p className="artistDetailText">{name}</p>
</div>

.artistDetailImage {
  background-size: cover;
  background-position: top;
  width: 100%;
  height: 300px;
  filter: contrast(60%);
}

.artistDetailText {
  width: 100%;
  font-size: 20px;
  text-align: left;
  padding-left: 5px;
  position: relative;
  top: 240px;
  filter: none; //Have also tried contrast(100%), brightness(1), etc.
  color: white;
}

这个答案似乎有效,但我希望有更好的方法来做到这一点。 https://stackoverflow.com/a/32677739/3010955

1 个答案:

答案 0 :(得分:1)

您将无法重置子元素的过滤器,但您可以将两者都包含在容器div中,然后相应地定位<p>

.container-div {
  position: relative;
}

.artistDetailImage {
  background-size: cover;
  background-position: top;
  width: 100%;
  height: 300px;
  filter: contrast(60%);
}

.artistDetailText {
  width: 100%;
  font-size: 20px;
  text-align: left;
  padding-left: 5px;
  position: absolute;
  top: 240px;
  color: white;
}
<div class="container-div">
  <div class="artistDetailImage" style="background-image: url('http://static.pexels.com/photos/33688/delicate-arch-night-stars-landscape.jpg');">
  </div>
  <p class="artistDetailText">NAME</p>
</div>