简体   繁体   English

伪元素格式不起作用

[英]Pseudo-element formatting not working

I have this CSS:我有这个 CSS:

sqrt::before {
  border: none;
  content: "√";
}
sqrt {
  content: attr(expr);
  border-top: 1px solid black;
}

The ::before pseudo-element has a border. ::before伪元素有一个边框。

I intentionally specified border: none;我特意指定了border: none; to avoid this.为了避免这种情况。

There is no border on the ::before . ::before上没有边界。 The issue is that your ::before -element is inside the sqrt -element.问题是您的::before -element 位于sqrt -element 内。

Try this code:试试这个代码:

sqrt::before {
  border: none;
  content: "√";
  position: absolute;
  left: 0;
}
sqrt {
  content: attr(expr);
  border-top: 1px solid black;
  margin-left:2px;
}

It positions the ::before absolute to the sqrt -element, and moves the sqrt -element away from the ::before , therefore creating the desired effect.它将::before绝对定位到sqrt元素,并将sqrt元素从::before移开,从而创建所需的效果。

Working JSFiddle工作 JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM