HTML   发布时间:2022-04-14  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了html – 为什么在Chrome中可以选择伪元素,除了最后一个,使用CSS counter()函数时?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
背景:

伪元素不应该是可选择的,因为它们是未生成DOM的CSS生成的内容.

题:

问题是:

为什么在内容属性中使用CSS counter()函数时,Chrome中可以选择伪元素(最后一个除外)?

插图:

代码:

jsFiddle

body {
  margin: 0;
}
ul {
  margin: 0;
  padding: 0;
  height: 100vh;
  list-style: none;
  display: flex;
  text-align: center;
  justify-content: center;
  align-items: center;
  counter-reset: list-items;
}
li {
  flex: 1;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  counter-increment: list-items;
}
li:first-child {
  BACkground-color: forestgreen;
}
li:nth-child(2) {
  BACkground-color: whitesmoke;
  color: saddlebrown;
}
li:nth-child(3) {
  BACkground-color: firebrick;
}
li:hover {
  BACkground-color: black;
  color: white;
}
li::before {
  font-size: 10vw;
  content: counter(list-items,upper-alpha);
}
<main>
  <nav>
    <ul>
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </nav>
</main>

笔记:

转载于ChromeVersión53.0.2785.143 m(64位)/ Windows 10.

>这不会发生在FF和Edge.
>可以使用前缀属性来解决-webkit-user-SELEct:none;在伪元素.
> Flexbox与该问题无关,在演示中用于说明的目的.

解决方法

因为周围没有负空间.如果你添加一些空间可以达到想要的效果 jsfiddle with the solution.

在现实生活中,相当于用一只手从地板上抓住一个大盒子.如果你的手在地板和箱子之间有一点空间,它更容易拉开.

ul {
  margin: 0 10px;
  padding: 0;
  height: 90vh;
  list-style: none;
  display: flex;
  text-align: center;
  justify-content: center;
  align-items: center;
  counter-reset: list-items;
}

大佬总结

以上是大佬教程为你收集整理的html – 为什么在Chrome中可以选择伪元素,除了最后一个,使用CSS counter()函数时?全部内容,希望文章能够帮你解决html – 为什么在Chrome中可以选择伪元素,除了最后一个,使用CSS counter()函数时?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。