简体   繁体   中英

CSS Selectors: if div's class name contains AT LEAST one char

What is the correct CSS selector if I want to know if there's at least one character in an element's class name?

I use this to know if the div class name inside .bar begins with "foo-":

.bar div[class^="foo-"] {display: block;}

But how do I check if there's just at least one char (letter or number or special char) in the class name?

You can check if an element has an empty or missing class attribute like this:

 div { color: red; } /* has a class attribute with at least one character */ div[class=""] { color: blue; } /* has an empty class attribute */ div:not([class]) { color: green; } /* has no class attribute */ 
 <div class="foo">foo</div> <div class="">bar</div> <div>baz</div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM