CSS与正则表达式的ID [英] Css with regex for id

查看:102
本文介绍了CSS与正则表达式的ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只希望第一个和第三个id为红色.那怎么可能?

I just want the first and third id to be red. How that possible?

HTML& CSS:

#sections div[id^='s.*0'] {
    color: red;  
} 

<div id="sections">
    <div id="s10">one</div>
    <div id="s2">two</div>
    <div id="s30">three</div>
    <div id="t1">four</div>
</div>

推荐答案

您可以为此使用特殊的CSS选择器:id$='0'表示id以0结束,而id^='s'表示id以s开头.

You can use special CSS selector for that: id$='0' means id ends with 0 and id^='s' means id begins with s.

#sections div[id$='0'][id^='s'] {
    color: red;  
}

<div id="sections">
<div id="s10">one</div>
<div id="s2">two</div>
<div id="s30">three</div>
<div id="t1">four</div>
</div>

这篇关于CSS与正则表达式的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆