CSS选择器-分组选择器
约 157 字小于 1 分钟
2025-10-15
也被称为并集选择器,多个元素具备相同样式时,可以将不同的选择器组合在一起,使用逗号分割。
基本语法:
选择器1,
选择器2,
选择器3 {
样式规则;
}使用示例:
style.css
/* 为不同元素类型的相同类名应用统一样式 */
button.btn-primary,
a.btn-primary,
input[type="submit"].btn-primary {
background-color: #007bff;
color: white;
padding: 10px 20px;
}index.html
<button class="btn-primary">主要按钮</button>
<a href="#" class="btn-primary">链接按钮</a>
<input type="submit" class="btn-primary" value="提交按钮">