代码之家  ›  专栏  ›  技术社区  ›  Nevin

Chrome开发工具为伪元素的悬停突出显示了错误的区域

  •  0
  • Nevin  · 技术社区  · 6 年前

    我有一个奇怪的问题,当我悬停在伪元素上时( ::before )在这里,突出显示似乎已关闭。

    Screenshot

    给出的CSS为:

    .testimonial__quote::before {
          content: open-quote;
          font-size: 11.25rem;
          width: 4.0625rem;
          height: 3.4375rem;
          position: absolute;
          color: #fbce07;
          display: block;
          font-style: italic;
          font-family: Arial, Helvetica, sans-serif;
    }
    

    HTML:

    <div class="testimonial__quote-container">
      <blockquote class="testimonial__quote">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean finibus lorem eu aliquet fermentum. Vestibulum ante ipsum
        primis in faucibus orci luctus.
      </blockquote>
      <p class="testimonial__author">- Scuderia Ferrari</p>
    </div>
    

    我要找的是有过类似经历的人。我不能像一些人建议的那样发布JSFIDLE,因为它是不可复制的。

    2 回复  |  直到 6 年前
        1
  •  2
  •   3rdthemagical    6 年前

    这是正常的行为。 Jsfiddle
    您已设置 width height 对于块元素(在您的情况下,它由 ::before 伪元素)。但文字字体太大,符号太多 " 大小容器“脱落”。


    在下面的图片中,我删除了 宽度 身高 属性。现在,根据块内容计算块大小(它是 “” 符号)。

    enter image description here


    添加以下样式以查看角色是否适合容器:

    overflow: hidden;
    outline: 1px solid red;
    

    enter image description here


    所以我认为你不应该 宽度 身高 到该元素。或者你可以使用 svg 具有固定大小的元素或图像。

        2
  •  1
  •   Nitin Patil    6 年前

    请检查一下这把小提琴。注意:当您使用 position:absolute 不要忘记属性顶部、左侧、右侧、底部,

    https://jsfiddle.net/Lbctgyea/5/