本文介紹了如何選擇 ID 以特定字符串開頭和結尾的所有元素?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在 CSS 中,如何選擇所有 <tr>
元素,它們的 id
以 section_
開頭并以 _dummy 結尾
?
In CSS, how can I select all <tr>
elements where their id
begins with section_
and ends with _dummy
?
例如我想選擇樣式并將其應用到以下 <tr>
的:
E.g. I'd like to select and apply styles to the following <tr>
’s:
<tr id="section_5_1_dummy">
<td>...</td>
</tr>
<tr id="section_5_2_dummy">
<td>...</td>
</tr>
推薦答案
下面的 CSS3 選擇器將完成這項工作:
The following CSS3 selector will do the job:
tr[id^="section_"][id$="_dummy"] {
height: 200px;
}
^
表示 id
應該以什么開頭.
The ^
denotes what the id
should begin with.
$
表示 id
應該以什么結尾.
The $
denotes what the id
should end with.
id
本身可以替換為另一個屬性,例如 href
:
id
itself can be replaced with another attribute, such as href
, when applied to (for example) <a>
:
a[href^="http://www.example.com/product_"][href$="/about"] {
background-color: red;
}
這篇關于如何選擇 ID 以特定字符串開頭和結尾的所有元素?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!