我试图用"过滤器"属性给DIV(背景图片(发出悬停效果。但是它对应该结束的另一个Div(我的文本(产生了影响。我应用了Z-Index属性(不忘记Divs的位置(,但它行不通。您会看到,我的文字也很模糊,不应该这样做。你能告诉我我的代码怎么了?
这是显示我的问题的codepen:https://codepen.io/gillian-d/pen/qmqeqy
html
<div class="container">
<div class="row">
<div class="col-sm-6 left_part-padding">
<div class="left_part">
<div class="left_part_content">
Left part
</div>
</div>
</div>
</div>
CSS
.container {
margin-right: auto;
margin-left: auto;
}
.left_part {
height: 40vh;
position: relative;
z-index: 0;
background-image: url(img/book2.jpeg);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
background-color: #000;
box-shadow: 0 50px 60px 0 rgba(0,0,0,.35);
border-radius: 10px;
}
.left_part:hover {
-webkit-filter: blur(5px);
filter: blur(5px);
-webkit-transition: .5s ease-in-out;
position: relative;
z-index:0;
}
.left_part_content:hover {
color: #fed136;
position: relative;
z-index: 2;
}
.left_part-padding, .right_part-padding, .bottom_part-padding {
padding-left: 10px;
padding-right: 10px;
}
.left_part_content {
color: white;
font-family: "Raleway", Helvetica, Arial, sans-serif;
text-transform: uppercase;
font-size: 1.2rem;
font-weight: 400;
letter-spacing: .300em;
margin-right: -.300em;
text-align: center;
vertical-align: middle;
line-height: 40vh;
position: relative;
z-index: 2;
}
非常感谢!
当您对元素添加效果时,在大多数情况下,他们的孩子也会受到影响,因此在这种情况下,您可以为background-image
更新的codepen
更改了CSS规则
.left_part {
height: 40vh;
position: relative;
background-color: #000;
box-shadow: 0 50px 60px 0 rgba(0,0,0,.35);
border-radius: 10px;
}
.left_part::before {
content: '';
position: absolute;
top: 0; left: 0;
width: 100%;
height: 100%;
background-image: url(http://lorempixel.com/500/200/nature/1/);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
background-color: #000;
border-radius: 10px;
}
.left_part:hover::before {
-webkit-filter: blur(5px);
filter: blur(5px);
}
在这里查看:
https://codepen.io/anon/pen/emnpvz
我将文本零件元素从易用的背景div中取出,现在都有相同的父母。接下来,我以不同的方式求解了中心(绝对位置,顶部和剩余50%, transform: translate(-50%, -50%)
。然后,我将 pointer-events: none;
应用于文本层,以便悬停在下面。我添加了一个不同的悬停规则,影响文本 - 请参阅我的Codepen。HTH