【问题标题】:Psuedo-element ::before is not displaying伪元素 ::before 不显示
【发布时间】:2020-02-15 07:21:18
【问题描述】:

伪元素存在于DOM中,但不可见。

我试过摆弄许多不同的选项,但我看不出有什么问题。 div 元素被包裹在一个空的 span 中,并在其中被调用。

style.scss

.tickBox {
  display: inline-block;
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  margin-top: 8px;
  margin-right: 8px;
  background-color: $grey6;
  overflow: visible;

  &::before{ 
    content: '';
    position: absolute;
    top: .9em;
    left: -4em;
    width: 4em;
    height: .3em;
    background: $grey6;
    z-index: -1;
  }
}

tickbox.js

const TickBox = () => (
  <div styleName={'tickBox'} />
);

复选框圆圈显示正确,当我在 DOM 元素查看器中将鼠标悬停在它上面时,我可以看到 ::before 伪元素在那里并且形状正确,但它没有显示。

【问题讨论】:

  • 添加z-index:0到父元素
  • z-index: -1 会将伪元素定位在tickBox 背景的之后。这是你想要发生的事情吗?

标签: css reactjs sass


【解决方案1】:

您目前似乎没有使用伪元素。试试这个设置 .help-tip 到 .help-tip::after 并给 content: "" 和

display: inline-block:
    .help-tip::after {
        content: "";
        display: inline-block;
        cursor: pointer;
        width: 10px;
        height: 10px;
        background-repeat: no-repeat;
        background-image: url("/assets/small-help-icon.gif");
    }

【讨论】:

  • 你在回答不同的问题吗?
【解决方案2】:

问题在于z-index 使它像999。

【讨论】:

  • 这工作谢谢!计时器允许时将接受答案
  • 快乐是我的 :)
猜你喜欢
  • 2016-05-24
  • 2015-09-12
  • 2013-06-15
  • 1970-01-01
  • 2014-02-08
  • 2018-09-23
  • 1970-01-01
  • 1970-01-01
  • 2019-11-25
相关资源
最近更新 更多