html - 在悬停 p 标签颜色没有改变
问题描述
在悬停时,我正在更改背景颜色和文本颜色,悬停时背景颜色会更改,但 p 标签文本颜色不会更改。
帮帮我,伙计们
HTML
<div id="groupInsurance" class="group-insurance">
<img src="images/group-insurance.png" class="insuranceIcon g-img">
<p class="insuranceText">GROUP<br>INSURANCE</p>
</div>
CSS
#groupInsurance {
float: left;
width: 145px;
height: 125px;
background-color: #EEEEEE;
text-align: center;
cursor: pointer;
}
#groupInsurance:hover {
background-color: #1E8449;
color: #fff;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
.insuranceText {
font-size: 12px;
font-weight: bold;
padding-top: 20px;
color: #505050;
}
解决方案
那是因为您在 p 标签上设置了颜色,因此它变得比您在父元素上执行的悬停更具体。试试下面
#groupInsurance {
float: left;
width: 145px;
height: 125px;
background-color: #EEEEEE;
text-align: center;
cursor: pointer;
}
#groupInsurance:hover {
background-color: #1E8449;
color: #fff;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
#groupInsurance:hover > .insuranceText {
color: #fff;
}
.insuranceText {
font-size: 12px;
font-weight: bold;
padding-top: 20px;
color: #505050;
}
<div id="groupInsurance" class="group-insurance">
<img src="images/group-insurance.png" class="insuranceIcon g-img">
<p class="insuranceText">GROUP<br>INSURANCE</p>
</div>
推荐阅读
- java - osgi NoClassDefFoundError - jar 目录
- spring-cloud-contract - Wiremock 请求与多部分不匹配
- angular - 带有订阅的 Angular Auth Guard
- python - Json 转换为 csv 文件但数据没有逐列跟随
- python - 如何为 CustomMessage_AdminCreateUser 触发器发送自定义消息?
- angular - 有没有办法在禁用 CSRF 的同时保留 Spring 默认登录页面?
- angular - SASS 无效的属性值
- javascript - 在 Angular 8 应用程序中获取选项配置的打字稿错误
- java - 同步访问相同文件,并发访问不同文件
- c++ - 循环多个枚举