如何将CSS样式块应用于多个不同的类?例如,我有
<div class="foo">...</div>
<div class="bar">...</div>
...
.foo .bar ??? // This selector should apply to both classes
{
font-size:50%;
...
}
答案 0 :(得分:16)
.foo, .bar
{
font-size:50%;
...
}
答案 1 :(得分:6)
使用逗号:
.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>