我使用的是WordPress,所以我写了自定义颜色来更改悬停时框的背景颜色,但是它不起作用
#project1 {
height: 100px;
width: 33.33%;
background-color: red !important;
}
#project1:hover {
background-color: blue;
color: white;
}
<div id="project1"></div>
答案 0 :(得分:3)
!important
规则不会被没有!important
的新规则覆盖。
或者从第一个声明中删除!important
,或者如果绝对必须保留它,请将其也添加到:hover
声明中。
#project1 {
height: 100px;
width: 33.33%;
background-color: red !important;
}
#project1:hover {
background-color: blue !important;
color: white;
}
<div id="project1"></div>
答案 1 :(得分:1)
尝试从第一条规则中删除!important
#project1{
background-color: red;
}
#project1:hover {
background-color: blue;
color: white;
}
此外,倾向于避免放置!important,而是使用父选择器的更好组合来进行覆盖。