How to apply CSS to elements that have multiple classes?
Is there a way to apply a style to elements that contain multiple classes?
Example
<div class="foo" > foo </div>
<div class="foo bar" > foo bar </div>
<div class="bar" > bar </div>
I only want to modify the styling of the element that contains class "foo bar". The XPath information would be开发者_运维百科 something like //div[contains(@class,"foo") and contains(@class,"bar")]
. Any ideas for pure CSS, w/o having to create a unique class?
Like this:
.foo { background: red; }
.bar { background: blue; }
.foo.bar { background: purple; }
Solutions
-
.foo.bar { ... }
-
[class="foo bar"] { ... } // explicit class name
-
[class~="foo"][class~="bar"] { ... } // inclusive class name
精彩评论