【发布时间】:2018-05-16 02:10:58
【问题描述】:
我试图在按下按钮时将 css 字体颜色更改为白色,但是我目前可以做到这一点的唯一方法是使用 !important 并强制更改颜色。有没有办法在不使用 !important 的情况下做到这一点?这是我的代码:
目前按钮字体颜色变为 .modal-close 的背景颜色,除非我使用 !important 强制它变为白色。有什么方法可以在不使用 !important 的情况下使其正常工作?任何帮助将不胜感激。
.modal-close {
width: 30px;
height: 30px;
border-radius:30px;
border: 1px solid $gray-light;
font-size: 14px;
font-weight: 200;
}
.modal-close-x {
position: relative;
right: 3px;
bottom: 4px;
}
.modal-close:focus {
outline: 0;
}
.modal-close:active {
background: #41b97c;
color: #ffffff; /* want this to work without !important */
border: 1px solid #41b97c;
}
.modal-close:hover {
border: 1px solid #41b97c;
color: #41b97c;
}
<button class="modal-close pull-right" aria-label="Close" >
<span class="modal-close-x" aria-hidden="true">×</span>
</button>
【问题讨论】:
-
:modal-close:active和.modal-close:hover具有相同的特异性。所以后一个优先。
标签: html css button pseudo-class