Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 804
StuperUser Avatar asked Jul 29 '11 14:07

StuperUser


People also ask

Can you use wildcard in CSS selector?

Wildcard selectors allow you to select multiple matching elements. In CSS, three wildcard selectors exist i.e. $, ^, and * The * wildcard is known as the containing wildcard since it selects elements containing the set value. With the ^ wildcard, you get to select elements whose attribute value starts with the set ...

What is the purpose of * wildcard in the selector?

Wildcard selector is used to select multiple elements simultaneously. It selects similar type of class name or attribute and use CSS property. * wildcard also known as containing wildcard.

What is the use of * In attribute selector?

The [attribute*="value"] selector is used to select elements whose attribute value contains a specified value.

What selector is used as a wildcard character?

Your answerAsterisk (*): It is used for replacing 1 or more characters from a selector attribute.


1 Answers

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

like image 64
BoltClock Avatar answered Sep 19 '22 19:09

BoltClock