【发布时间】:2015-09-12 00:53:19
【问题描述】:
我正在学习 CSS,我得到了我想要的结果,但前提是我使用了 ! important; 规范。我不明白为什么我不能覆盖继承一个类的属性并覆盖一个属性。
form button.minor-action,
#profile-left a.action,
.minor-action {
display: inline-block;
background: @lightBlue;
color: white;
padding: 0 1.2em;
border-radius: 4px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
-ms-border-radius: 4px;
text-decoration: none;
text-align: center;
font-weight: bold;
border: none;
height: 25px;
margin-top:1.0em;
line-height:25px;
white-space: nowrap;
&:visited {
color: white;
}
&:hover, &:active, &:focus {
background-color: darken(@lightBlue, 10%);
text-decoration: none;
}
&.call-to-action {
background-color: @pink;
&:hover, &:active, &:focus {
background-color: darken(@pink, 10%);
text-decoration: none;
}
}
}
.extra-questions {
margin-top: 0em !important;
}
我想如果我将上述样式用于按钮:
<button id="add_question" class="extra-questions minor-action">{% trans "Lägg till ny" %}</button>
那么我就不必使用! important; 语句,并且如果没有它,覆盖也可以工作,但事实并非如此。我错过了什么?你能帮我理解为什么没有! important 语句它不能工作,或者告诉我没有! important; 的方法吗?
【问题讨论】: