html - 为什么 h2 和 h4 标签在悬停状态下不会改变颜色?
问题描述
我试图在将两个链接悬停时更改它们的文本颜色,但颜色没有改变?是什么原因?
h2 {
color: green;
}
h4 {
color: pink;
}
a:hover {
color: lightblue;
}
a {
text-decoration: none;
color: black;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a href="#">
<h2>This is a header</h2>
<h4>This is another header</h4>
</a>
解决方案
元素是元素的任何颜色。
默认情况下,标题inherit
的颜色是其父元素的颜色。
div {
color: blue;
}
<div>
The div is blue
<h1>The h1 is blue</h1>
</div>
<h1>The h1 is black</h1>
但是如果你明确设置它,那么它就是你设置的任何颜色......</p>
div {
color: blue;
}
h1 {
color: pink
}
<div>
The div is blue
<h1>The h1 is pink</h1>
</div>
<h1>The h1 is pink</h1>
您正在设置a
to lightblue
,但由于标题不是color: inherit
他们没有继承它。:hover
无关紧要。
编写一个针对标题的选择器(例如a:hover h2, a:hover h4 { … }
)
推荐阅读
- hashicorp-vault - 使用 Approle Harshcorp Vault 生成令牌后权限被拒绝
- python - Get average by word in column
- python - 如何在 CalibratedClassifierCV 之后将自定义 RuleBasedClassifier 添加到 sklearn 管道?
- java - JPA 中的 MongoDB 本机查询
- r - ggplot2 箱线图的两种不同颜色/图案方案
- android - Android 谷歌地图仅在停止后捕获相机位置
- python - 如何按降序对数据表框架进行排序
- javascript - 错误:反应本机应用程序内的 html 文本内的 Youtube 链接
- java - 如何使用 Java 找到 2 个像素图像之间的相似性
- constraints - 系统verilog中约束中的多个foreach语句使用