CSS 如何选择ID以特定字符串开头和结尾的所有元素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16009755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to select all elements whose ID starts and ends with specific strings?
提问by Danny Beckett
In CSS, how can I select all <tr>
elements where their id
begins with section_
and ends with _dummy
?
在 CSS 中,如何选择<tr>
以id
开头section_
和结尾的所有元素_dummy
?
E.g. I'd like to select and apply styles the following <tr>
s:
例如,我想选择并应用以下样式<tr>
:
<tr id="section_5_1_dummy">
<td>...</td>
</tr>
<tr id="section_5_2_dummy">
<td>...</td>
</tr>
回答by Danny Beckett
The following CSS3 selector will do the job:
以下 CSS3 选择器将完成这项工作:
tr[id^="section_"][id$="_dummy"] {
height: 200px;
}
The ^
denotes what the id
should begin with.
该^
表示什么id
应该开始。
The $
denotes what the id
should end with.
该$
表示什么id
应该结束。
id
itself can be replaced with another attribute, such as href
, when applied to (for example) <a>
:
id
本身可以替换为另一个属性,例如href
,当应用于(例如)时<a>
:
a[href^="http://www.example.com/product_"][href$="/about"] {
background-color: red;
}