Select element that has a class that starts with a

2019-07-27 05:41发布

问题:

This question already has an answer here:

  • Match all elements having class name starting with a specific string [duplicate] 3 answers

Is it possible to select a element that has a class that starts with a string?

There is

 .element[class^="icon-"]{
   ...
 }

but it fails when the class is preceded by another class or whatever :(

回答1:

Yes, you can!

.element[class^='icon-'],
.element[class*=' icon-'] {
  ...
}

See it in action: http://jsfiddle.net/caio/mxUxR/.



标签: css css3 class