在css中使用正则表达式? [英] Using regular expression in css?
问题描述
我有一个HTML网页,其中divs的 s1 , s2 形式的 ID 等。
I have an html page with divs that have id(s) of the form s1, s2 and so on.
<div id="sections">
<div id="s1">...</div>
<div id="s2">...</div>
...
</div>
我想将css属性应用到这些节/ divs的子集。但是,每次添加 div 时,都必须单独为此部分添加css。
I want to apply a css property to a subset of these sections/divs (depending upon the id). However, every time I add a div, I have to add the css for the section separately like this.
//css
#s1{
...
}
$ b b
在css中有正则表达式,我可以用来将样式应用到一组 div 。
推荐答案
您可以管理选择这些元素,没有任何形式的正则表达式像以前的答案显示,但直接回答问题,是的,你可以在选择器中使用正则表达式:
You can manage selecting those elements without any form of regex as the previous answers show, but to answer the question directly, yes you can use a form of regex in selectors:
#sections div[id^='s'] {
color: red;
}
这意味着在#sections中选择任何div元素
That says select any div elements inside the #sections div that have an ID starting with the letter 's'.
请参阅这里。
这篇关于在css中使用正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!