Technology Inside Out!

Index ¦ Archives ¦ Atom ¦ RSS

CSS Regex selector - Using Regular Expression in CSS

Just like JQuery, CSS also offer a great way to filter out elements with selectors using Regular Expressions.

Selecting on  Attribute and value

[[att=str]]{style="font-family: 'courier new', courier;"} :- attribute value is exactly matching to str

[[att*=str] ]{style="font-family: 'courier new', courier;"}:-  attribute value contains str - value can contain str anywhere either in middle or at end.

[[att\^=str]]{style="font-family: 'courier new', courier;"} :- attribute value starting with str

[[att\$=str]]{style="font-family: 'courier new', courier;"} :- attribute value ends with str

[att] :-  Elements which contain attribute att with any value

Example:

Applying CSS with Pseudo-class :not

This quite interesting using :not selector to filter out on element properties. Using not selector you can distinguish them from other elements. In this selector also you can use regular expressions to find your elements.

For example:

 input:not([DISABLED]){
   background-color: yellow;
 }

© The Geeky Way. Built using Pelican. Theme by Giulio Fidente on github.

Disclaimer Privacy policy