2010-01-23 27 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>