开发者

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


  1.  .foo.bar { ... }
    
  2.  [class="foo bar"] { ... }             // explicit class name
    
  3.  [class~="foo"][class~="bar"] { ... }  // inclusive class name
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜