html - 如何使用 css 定位 id ="last_name[]_field"

标签 html css css-selectors special-characters

我正在使用 wordpress 插件,开发人员使用名称中的 [] 字符创建了 ID。

我不知道如何用 css 定位它们...

<p id="shipping_city[]_field">stuff</p>

所以我试试

#shipping_city[]_field {font-size:24px;}

或者什么的.. 没有运气。

有没有人遇到过这种事情?

我不想更改开发人员的 html,因为这是一个表单条目,我认为 [] 有一个目的...

最佳答案

您必须转义特殊字符 - 请参阅 Link

The following characters have a special meaning in CSS: !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, `, {, |, }, and ~.

There are two options if you want to use them. Either you use the Unicode code point — for example, the plus sign (+) is U+002B, so if you would want to use it in a CSS selector, you would escape it into \2b (note the space character at the end) or \00002b (using exactly six hexadecimal digits).

The second option is far more elegant though: just escape the character using a backslash

#shipping_city\[\]_field {
  font-size: 24px;
  color: red;
}
<p id="shipping_city[]_field">stuff</p>

关于html - 如何使用 css 定位 id ="last_name[]_field",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29284181/

相关文章:

css - 当 CSS 规则在 Chrome 的元素检查器中显示为灰色时,这意味着什么?

javascript - 是否可以在 Javascript 中将选择器作为函数参数传递?

CSS 样式 "leaking"到非预期元素,为什么会发生以及如何防止?

javascript - 在html页面中制作线性电位器

html - 非语义网格。为什么最后一个 div 被移到了其他 div 的下面?

html - 为什么向内联 block div 添加跨度会改变它的布局?

html - 带有文章的 CSS 伪类

javascript - 为表格中的第一个可见行重新应用 css 规则

html - 为什么 CSS min-width 属性不强制 div 具有指定的最小宽度?

html - 使下划线 CSS 过渡改变方向