html - 一个 anchor 中的多种下划线颜色

标签 html css

我想,在一个 anchor 内</a> , 有两种不同的下划线颜色。像这样:

<a href="somehref">
    <span>This text should underline RED on `a` hover</span>
    <span>This text should underline GREY on `a` hover</span>
</a>

我可以添加text-decoration到悬停时的每个跨度,但这会导致每条线单独悬停。我想要它,以便当我将鼠标悬停在 </a> 中的任何位置时两个 span 的字体都带有下划线 color继承。

这可能吗?

注意:我知道 text-decoration-color但由于支持有限,我无法使用它。

最佳答案

是这样的吗?您可以使用 anchor 的 :hover CSS 伪类来设置其子项和后代的样式。

这是对 CSS 的引用 childdescendant选择器。

a {
  color: black;
  text-decoration: none;
}
a span:first-child {
  color: red;
}
a span:last-child {
  color: grey;
}
a:hover span {
  text-decoration: underline;
}
<a href="somehref">
  <span>This text should underline RED on `a` hover</span>
  <span>This text should underline GREY on `a` hover</span>
</a>

关于html - 一个 anchor 中的多种下划线颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38481240/

相关文章:

php - 如何在php mysql中访问复选框的值

html - CSS 图片(动态大小)在右上角,其他元素填充空间

css - IE6 - 元素弹出和弹出

javascript - 当所有元素都标记为绿色时,如何计算变为绿色并显示 <p> 的元素?

css - 如何为查看者提供自定义 CSS 选项

javascript - 从 div 获取特定的 div 类并基于该类执行函数

jquery - 具有自定义背景图像的可变高度 div - 最好的技术是什么?

html - CSS 颜色不加载按钮

html - 搜索框上的填充不适用于 IE 和 Bootstrap 菜单栏的 chrome

css - Twitter Bootstrap 导航栏