将css样式应用于多个模式

rip*_*234 8 html css

如何将CSS样式块应用于几个不同的类?例如,我有

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

...

.foo .bar ???    // This selector should apply to both classes
{
  font-size:50%;
  ...
}
Run Code Online (Sandbox Code Playgroud)

Rol*_*man 6

使用逗号:

.foo, .bar {
....
}
Run Code Online (Sandbox Code Playgroud)

相反,将多个类应用于单个元素也是可能的:

<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>
Run Code Online (Sandbox Code Playgroud)