不同的图标不透明度

时间:2018-06-03 11:59:34

标签: css css3

我拥有的是好的。 唯一的问题是我希望图片signopacity: 0.3上有hoverstaropacity: 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;
&#13;
&#13;

1 个答案:

答案 0 :(得分:3)

不要将0.3不透明度应用于.sign div,因为它也会影响该星星,因为这个星星是其内容的一部分。改为定位图像:

&#13;
&#13;
.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;
&#13;
&#13;