在元素中组合CSS类

rod*_*dbv 4 css

这可能是我做过的最愚蠢的问题,但为什么下面的文字没有呈现红色?

<html>
  <style>
  .c1 .c2 { 
     color: red; 
  }
  </style>
  <body>
     <span class="c1 c2">This should be red</span>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

编辑:我想匹配包含c1和c2类的元素,如上面的例子,不能少.

Joh*_*ica 9

.c1 .c2匹配c1元素中的c2元素,就像html body匹配html元素中的body元素一样.删除空格以匹配两个类的元素:

.c1.c2 { 
   color: red; 
}
Run Code Online (Sandbox Code Playgroud)

  • @rodbv - 仅限IE6. (3认同)