是否可以在属性选择器的中间使用CSS通配符?

时间:2021-06-03 19:49:46

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

我有一些生成的CSS并且想使用一些CSS来选择。

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

Using on lorem and Ipsum disregarding Index. Something similar to:

用于洛伦和Ipsum忽略指标。类似于:

p#lorem*Ipsum
{
}

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

我可以生成更多的类,但是不知道CSS是否可以做到这一点。

1 个解决方案

#1


43  

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:

您不能使用这样的通配符,但是要获得所需的结果(ID以lorem开头,以Ipsum结尾),您可以使用带有选择器的属性starwith和end,如下所示:

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.

请记住,通过链接像这样的多个属性选择器(以及p类型选择器),您将在相同的元素上执行并匹配所有的属性选择器。

jsFiddle demo

jsFiddle演示

#1


43  

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:

您不能使用这样的通配符,但是要获得所需的结果(ID以lorem开头,以Ipsum结尾),您可以使用带有选择器的属性starwith和end,如下所示:

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.

请记住,通过链接像这样的多个属性选择器(以及p类型选择器),您将在相同的元素上执行并匹配所有的属性选择器。

jsFiddle demo

jsFiddle演示