2010-01-23 54 views
8

如何将CSS样式块应用于多个不同的类?举例来说,我有将css风格应用于多种模式

<div class="foo">...</div> 
<div class="bar">...</div> 

... 

.foo .bar ??? // This selector should apply to both classes 
{ 
    font-size:50%; 
    ... 
} 

回答

5

使用逗号:

.foo, .bar { 
.... 
} 

反过来,应用多个类的单个元素也是可能的:

<html> 
<head> 
    <style type="text/css"> 
     .foo { 
     } 
     .bar { 
     } 
    </style> 
</head> 
<body> 
    <!-- 
     space separated list of classnames 
     to apply multiple css classes to a single element. 
    --> 
    <div class="foo bar">...</div> 
</body> 
</html>