开发者

Is it possible to use a CSS wildcard in the middle of an attribute selector?

开发者 https://www.devze.com 2023-03-24 07:48 出处:网络
I have some generated CSS and would like to use some css that could select e.g. <p id=\"loremIndexIpsum\">Text in here</p>

I have some generated CSS and would like to use some css that could select e.g.

<p id="loremIndexIpsum">Text in here</p>

Using on lorem and Ipsum disregarding Index. Something similar 开发者_运维知识库to:

p#lorem*Ipsum
{
}

I can generate some more classes, but wondered if this was possible with CSS.


You can't use a wildcard like that, but to get the desired result (ID starts with lorem and ends with Ipsum) you can use the attribute starts-with and ends-with selectors instead, like so:

p[id^="lorem"][id$="Ipsum"]

Remember that by linking multiple attribute selectors like this (along with the p type selector), you're doing an AND match with all of them on the same element.

jsFiddle demo

0

精彩评论

暂无评论...
验证码 换一张
取 消