【问题标题】:SVG on hover: Image on hover SVG icon not working [duplicate]悬停时的 SVG:悬停 SVG 图标上的图像不起作用 [重复]
【发布时间】:2020-07-13 01:11:37
【问题描述】:

我正在处理一项任务。当悬停 SVG 图标不起作用时,在图像上。 我被困在我不正确的地方。请任何人,谁可以帮助得到这个。并指出我正确的方向。 提供的链接,我已编码codepen 提前致谢。

.image-box {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}
.fuss-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  display: block;
}
.fuss-icon { position: relative; }
 .fuss-icon {
    position: absolute;
    top: 50%;
    left: 40%;
    transform: translatey(-30px);
/*     display: none; */
}
.fuss-img img:hover object {
display: block;
}
<div class="image-box">
  <div class="fuss-img">
    <a href="#">
    <img src="https://i.ibb.co/xGz75Q3/pim-chu-294493-unsplash.jpg">
    </a>
    </div>
  <div class="fuss-icon">
    <object>
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="50pt" height="50pt" viewBox="0 0 50 50"><g id="surface24150293"><path style=" stroke:none;fill-rule:nonzero;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 25 2 C 12.308594 2 2 12.308594 2 25 C 2 37.691406 12.308594 48 25 48 C 37.691406 48 48 37.691406 48 25 C 48 12.308594 37.691406 2 25 2 Z M 25 4 C 36.609375 4 46 13.390625 46 25 C 46 36.609375 36.609375 46 25 46 C 13.390625 46 4 36.609375 4 25 C 4 13.390625 13.390625 4 25 4 Z M 18 13.25 L 18 36.75 L 19.5 35.875 L 36.5 25.875 L 37.96875 25 L 36.5 24.125 L 19.5 14.125 Z M 20 16.75 L 34 25 L 20 33.25 Z M 20 16.75 "></path></g></svg></object>
  </div>
</div>

【问题讨论】:

  • 根据您的结构,您的选择器是错误的。它应该更像.fuss-img:hover + .fuss-icon object
  • @Paulie_D:感谢您的快速回复,我会尝试您建议的代码。
  • @Paulie_D:我已经替换了代码,但它不起作用:(

标签: html css svg hover css-transitions


【解决方案1】:

请试试这个

jsfiddle link

.image-box {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.fuss-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 4px;
}

.fuss-icon {
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  position: absolute;
  opacity: 0;
  transition: opacity;
  transition-duration: 400ms;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
}

.fuss-icon object {
  position: absolute;
  top: 50%;
  left: 40%;
  margin-top: -25pt;
}

.fuss-img a:hover .fuss-icon {
  opacity: 1;
}
<div class="image-box">
  <div class="fuss-img">
    <a href="#">
      <img src="https://i.ibb.co/xGz75Q3/pim-chu-294493-unsplash.jpg">
      <span class="fuss-icon">
        <object>
          <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="50pt" height="50pt" viewBox="0 0 50 50">
            <g id="surface24150293">
              <path style=" stroke:none;fill-rule:nonzero;fill:rgb(100%,100%,100%);fill-opacity:1;" d="M 25 2 C 12.308594 2 2 12.308594 2 25 C 2 37.691406 12.308594 48 25 48 C 37.691406 48 48 37.691406 48 25 C 48 12.308594 37.691406 2 25 2 Z M 25 4 C 36.609375 4 46 13.390625 46 25 C 46 36.609375 36.609375 46 25 46 C 13.390625 46 4 36.609375 4 25 C 4 13.390625 13.390625 4 25 4 Z M 18 13.25 L 18 36.75 L 19.5 35.875 L 36.5 25.875 L 37.96875 25 L 36.5 24.125 L 19.5 14.125 Z M 20 16.75 L 34 25 L 20 33.25 Z M 20 16.75 "></path>
            </g>
          </svg></object>
      </span>
    </a>
  </div>
</div>

【讨论】:

  • 感谢您的所有努力:)
  • 我很乐意提供帮助。
  • 拜托,你能帮帮我吗..我还试图在悬停时获得一个带有图标的叠加层......任何想法..我试图得到那个..但它似乎不适合我。任何建议
  • 再次感谢您的所有努力.. 我实现了:)
  • 我已使用叠加层更新了我的帖子。
猜你喜欢
  • 2020-09-14
  • 2018-05-20
  • 2022-12-17
  • 2015-01-12
  • 1970-01-01
  • 2021-11-13
  • 1970-01-01
  • 2020-08-14
  • 2017-01-04
相关资源
最近更新 更多