我找不到解决我问题的方法。从Codepen中可以看到,我想对父元素应用滤镜,以使图像模糊。问题是文本子元素也变得模糊,当我尝试应用filter:none
时,它不会更改文本中的任何内容。为什么会这样呢?我该如何预防呢?谢谢。
.albums__item {
position: relative;
width: 500px;
height: 500px;
transition: all .4s;
}
.albums__img {
object-fit: cover;
width: 100%;
height: 100%;
}
.albums__item:hover {
filter: blur(2.5px);
}
.albums__item:hover>.albums__caption {
filter: none;
}
.albums__caption {
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
width: 85%;
text-align: center;
color: #fff;
font-size: 3rem;
font-weight: 300;
letter-spacing: 2.5px;
display: flex;
flex-direction: column;
}
.albums__caption--year {
margin-top: 6rem;
font-size: 3.5rem;
}
.albums__caption {
visibility: hidden;
opacity: 0;
transition: all .6s;
}
.albums__item:hover>.albums__caption {
visibility: visible;
opacity: 1;
}
<figure class="albums__item albums__item--1">
<img class="albums__img" src="https://pbs.twimg.com/media/DTVfQ4DX4AEYtmO.jpg" alt="Album image Koyu Antoloji">
<figcaption class="albums__caption">
<div class="albums__caption--name mb-md">Koyu Antoloji</div>
<div class="albums__caption--year">2017</div>
</figcaption>
</figure>
答案 0 :(得分:1)
将filter
放在图片上...而不是包装纸上
.albums__item:hover img {
filter: blur(2.5px);
}
.albums__item {
position: relative;
width: 500px;
height: 500px;
transition: all .4s;
}
.albums__img {
object-fit: cover;
width: 100%;
height: 100%;
}
.albums__item:hover img {
filter: blur(2.5px);
}
.albums__item:hover>.albums__caption {
filter: none;
}
.albums__caption {
position: absolute;
top: 45%;
left: 50%;
transform: translate(-50%, -50%);
width: 85%;
text-align: center;
color: #fff;
font-size: 3rem;
font-weight: 300;
letter-spacing: 2.5px;
display: flex;
flex-direction: column;
}
.albums__caption--year {
margin-top: 6rem;
font-size: 3.5rem;
}
.albums__caption {
visibility: hidden;
opacity: 0;
transition: all .6s;
}
.albums__item:hover>.albums__caption {
visibility: visible;
opacity: 1;
}
<figure class="albums__item albums__item--1">
<img class="albums__img" src="https://pbs.twimg.com/media/DTVfQ4DX4AEYtmO.jpg" alt="Album image Koyu Antoloji">
<figcaption class="albums__caption">
<div class="albums__caption--name mb-md">Koyu Antoloji</div>
<div class="albums__caption--year">2017</div>
</figcaption>
</figure>