如何选择ID以特定字符串开头和结尾的所有元素?

[英]How to select all elements whose ID starts and ends with specific strings?


In CSS, how can I select all <tr> elements where their id begins with section_ and ends with _dummy?

在CSS中,如何选择所有元素,其id以section_开头,以_dummy结尾?

E.g. I'd like to select and apply styles the following <tr>s:

例如。我想选择并应用以下的样式:

<tr id="section_5_1_dummy">
    <td>...</td>
</tr>

<tr id="section_5_2_dummy">
    <td>...</td>
</tr>

1 个解决方案

#1


43  

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[href^="http://www.example.com/product_"][href$="/about"] {
    background-color: red;
}
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/04/15/5fdad97dc2d097280d554d88363a8b0e.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告