【发布时间】:2018-07-30 08:54:01
【问题描述】:
我有一些代表“工具”的按钮。按钮的样式如下:
.button {
background-color: #DDDDDD;
border: none;
color: black;
border-radius: 8px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 12px;
padding: 8px 16px;
cursor: pointer;
}
.button:hover {
background-color: #4CAF50;
color: white;
}
当您单击其中一个时,我会更改背景颜色以突出显示您正在使用的工具,并重置未使用工具的背景,例如:
document.getElementById("buttonPencil").style.backgroundColor = "red";
document.getElementById("buttonEraser").style.backgroundColor = "#DDDDDD";
document.getElementById("buttonBucket").style.backgroundColor = "#DDDDDD";
问题在于,更改此样式后,悬停效果在这些按钮上不再正常工作(实际上只有按钮内的文本颜色会在悬停时发生变化)。 有人可以解释一下如何解决这个问题以及为什么会这样吗?
【问题讨论】:
-
内联样式在 CSS 中具有最高的特异性
标签: javascript css button hover