gpt4 book ai didi

html - 如何选择 ID 以数字开头的元素?

转载 作者:行者123 更新时间:2023-11-28 15:47:48 25 4
gpt4 key购买 nike

<div id="634670717473476800" align="center" style="width: 100%; overflow-y: hidden;" class="wcustomhtml">

我有上面的 HTML(自动生成,无法更改),我尝试在 CSS 中选择整个 DIV。页面上有几个“wcustomhtml”,所以 ID 是我唯一的选择。我认为很简单。

但我无法选择它,我不明白为什么。

#634670717473476800 和 div#634670717473476800 都无法选择 div。难道不能选一个纯数字的ID吗?

因此,如果它是有效的 HTML,那么有什么问题呢? Chrome 的检查元素和 Firebug 都不允许我根据检查器中的 ID 创建规则。

最佳答案

您可以使用属性选择器并选择 ID 属性来访问它:

[id='634670717473476800'] {
background-color: red;
}
<div id="634670717473476800" align="center" style="width: 100%; overflow-y: hidden;" class="wcustomhtml">div</div>

或者通过转义数字:

#\36 34670717473476800 {
background-color: green;
}
<div id="634670717473476800" align="center" style="width: 100%; overflow-y: hidden;" class="wcustomhtml">div</div>

引自 CSS character escape sequences :

If the first character of an identifier is numeric, you’ll need toescape it based on its Unicode code point. For example, the code pointfor the character 1 is U+0031, so you would escape it as \000031 or\31 .

Basically, to escape any numeric character, just prefix it with \3 andappend a space character ( ). Yay Unicode!

ID 属性 来自 HTML specification :

There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.

关于html - 如何选择 ID 以数字开头的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30938244/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com