返回博客

CSS 选择器详解:`[id~=footnotes]` 失效原因分析

深入探讨 CSS 选择器,特别是 `[id~=footnotes]`选择器失效的原因,并与`[id^='footnotes']` 进行比较。文章通过一个实际案例,解释了如何正确选择包含特定字符串的 ID 属性。

Mt.r
|

我实在是太菜了,一个前端,连这个都不会,还需要查?

<sup id="footnotes-ref-4:1">
  <a a href="#footnotes-def-4:1">注</a>
</sup>

怎么选择 id 带 footnotes-ref 的元素?下面的方法为啥不管用?

[id~='footnotes'] {
  user-select: none;
}

实现

群友逼哥 的提示下改成以 footnotes 开头的就生效了

[id^='footnotes'] {
  user-select: none;
}

后记

还是么想通为什么 [id~=footnotes] 不管用

这是逼哥的网站 - https://weather.zjinh.cn/

自嘲

一个快 3 年的前端,连这都没玩过,还要查资料确认,乐色 乐色 真的乐色 too low