【发布时间】:2020-07-10 23:17:50
【问题描述】:
在我的代码中,我的所有按钮都有一个通用表单:
input[type="button"],put[type="button"]:active,input[type="button"]:hover {
width: 172px;
height: 37px;
line-height: 2 !important;
margin: 11px 0px 0px 0px;
padding: 5px 150px 9px 5px;
line-height: 19px;
font-size: 12px;
}
但系统中的某些按钮的宽度是通用按钮的一半或三分之一。所以他们仍然是输入按钮并接收上面的 css,但我只想改变宽度,让它看起来像这样,而不使用 !important。
.thirdButton, .thirdButton:active {
width: 28px;
padding: 0;
background-position-x: 50%;
}
【问题讨论】:
-
您应该为它们添加另一个类或使用它们具有的另一个属性,以便它们具有更高的特异性,例如:
.thirdButton.myClass, .thirdButton.myClass:active -
类应该比一般选择器具有更高的特异性
-
@DaemonPainter 不“应该”;类选择器 比一般元素选择器具有更高的特异性。但是,attribute 选择器与类选择器在同一列中。
-
@Eduardo 阅读本文smashingmagazine.com/2007/07/…
标签: css css-selectors css-specificity