我拥有的是好的。
唯一的问题是我希望图片sign
在opacity: 0.3
上有hover
而star
有opacity: 1
,这意味着hover
上的全黑色}。现在似乎star
部分地从图片opacity
获取sign
并且不需要(您看到star
是灰色的。如何修复?
.div:hover .sign {
opacity: .3;
}
.div:hover > .sign::before {
opacity: 1;
}
.div .sign {
-webkit-transition: all 3.0s ease;
-moz-transition: all 3.0s ease;
-o-transition: all 3.0s ease;
-ms-transition: all 3.0s ease;
transition: all 3.0s ease;
position: relative;
}
.div .sign::before {
content: '\2605';
font-family: "fontello";
font-size: 5em;
color: #fff;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
color: black;
backface-visibility: hidden:
-webkit-transition: all 3.0s ease;
-moz-transition: all 3.0s ease;
-o-transition: all 3.0s ease;
-ms-transition: all 3.0s ease;
transition: all 3.0s ease;
}
.div .sign {
width: 150px;
height: 150px;
}
.div .sign img {
width: 100%;
}

<div id="wrapper">
<div class="div">
<div class="sign">
<img src="http://via.placeholder.com/150x150" alt="">
</div>
</div>
</div>
&#13;
答案 0 :(得分:3)
不要将0.3
不透明度应用于.sign
div,因为它也会影响该星星,因为这个星星是其内容的一部分。改为定位图像:
.div:hover .sign img {
opacity: .3;
}
.div:hover>.sign::before {
opacity: 1;
}
.div .sign img {
transition: all 3.0s ease;
}
.div .sign::before {
content: '\2605';
font-family: "fontello";
font-size: 5em;
color: #fff;
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
text-align: center;
color: black;
transition: all 3.0s ease;
}
.div .sign {
width: 150px;
height: 150px;
position: relative;
}
.div .sign img {
width: 100%;
}
&#13;
<div id="wrapper">
<div class="div">
<div class="sign">
<img src="http://via.placeholder.com/150x150" alt="">
</div>
</div>
</div>
&#13;