【问题标题】::hover works only when forced in the dev tools inspector:hover 仅在开发工具检查器中强制时有效
【发布时间】:2020-09-13 18:34:19
【问题描述】:

:hover 效果仅在通过开发工具强制执行时有效,但在鼠标悬停时无效。 我尝试将浏览器从 mozilla、chrome 更改为 safari 但没有运气 为什么会这样? 我希望文本(玛丽...)在我悬停时立即出现在图像上...

这是我的代码,

.story {
    width: 75%;
    color: $color-black;
    margin: 0 auto;
    background-color: $color-white;
    border-radius: 3px;
    padding: 9rem 6rem;
    padding-left: 9rem;
    font-size: $default-font-size;
    transform: skewX(-12deg);
& > * {
    transform: skewX(12deg);
}
&__shape {
    width: 17rem;
    height: 17rem;
    float: left;
    -webkit-shape-outside: circle(50% at 50% 50%);
    shape-outside: circle(50% at 50% 50%);
    -webkit-clip-path: circle(50% at 50% 50%);
    clip-path: circle(50% at 50% 50%);
    transform: translateX(-3rem) skewX(12deg);
    position: relative;
}
&__img {
    height: 100%;
    transform: translateX(-4rem) scale(1.4);
    backface-visibility: hidden;
    transition: all .5s;
}
&__caption {
    text-transform: uppercase;
    font-size: 1.7rem;
    position: absolute;
    top: 50%;
    left: 55%;
    transform: translate(-50%, 30%);
    transition: all .4s;
    color: $color-white;
    opacity: 0;
    &:hover {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}
    <div class="story">
        <figure class="story__shape">
            <img src="/img/nat-8.jpg" alt="Blonde" class="story__img">
            <figcaption class="story__caption">mary smith</figcaption>
        </figure>
    </div>

【问题讨论】:

  • 如果&amp;__caption 的颜色为白色,则无论不透明度如何,您在悬停元素时可能都看不到它。
  • 由于我在图像上超级强加文字,它是可见的......

标签: html css sass css-animations


【解决方案1】:

如果你想在图像上悬停时显示标题,如果你应用 :hover 到&amp;__shape 怎么样?

https://codepen.io/kreediam/pen/pojmEwJ

&__shape {
  width: 17rem;
  height: 17rem;
  float: left;
  -webkit-shape-outside: circle(50% at 50% 50%);
  shape-outside: circle(50% at 50% 50%);
  -webkit-clip-path: circle(50% at 50% 50%);
  clip-path: circle(50% at 50% 50%);
  transform: translateX(-3rem) skewX(12deg);
  position: relative;

  &:hover {
    .story__caption {
      opacity: 1;
      transform: translate(-50%, -50%);
    }
  }
}

【讨论】:

  • 顺便说一下,那支笔确实会显示标题,但我必须确保将鼠标悬停在标题上,与图像相比,它只占用很小的区域。
  • 谢谢,它按你的方式工作。我还在codepen中尝试了我的方法,它奏效了。但是,我想知道为什么它在我的项目中不起作用?你能给我一个相同的解释吗,将不胜感激。我只是浪费了一整天的时间来弄清楚......
  • 我以前去过那里,我感受到了你的痛苦。 :) :( 很难说为什么它在您的项目中不起作用。我建议注释掉 opacity: 0; 以确保标题有内容并且您将鼠标悬停在标题上,但话又说回来了将鼠标悬停在标题上将是您想要的体验。
猜你喜欢
  • 2014-10-20
  • 1970-01-01
  • 2020-02-09
  • 1970-01-01
  • 1970-01-01
  • 2015-11-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多