css - 带有 id 和 css 的标签

标签 css hyperlink anchor

我正在尝试输出一些具有特定悬停/事件/链接属性的链接:

a#links:link {
  color: red;
  text-decoration: none
}
a#links:visited {
  color: goldenrod;
  text-decoration: none
}
a#links:hover {
  color: maroon;
  text-decoration: none;
  font-variant: small-caps
}
<div id="links" class="right" style="margin-right:65px">
  <ul class="nobull" style="margin:0">
    <li><a href="http://com">This link</a>
    </li>
  </ul>
</div>

链接属性没有被采用。某处语法错误?我想不通。

最佳答案

a#links 选择一个链接 ID 不存在的 anchor 。您需要 #links a 来选择作为具有链接 ID 的 div 后代的 anchor 。

#links a:link {
  color: red;
  text-decoration: none
}
#links a:visited {
  color: goldenrod;
  text-decoration: none
}
#links a:hover {
  color: maroon;
  text-decoration: none;
  font-variant: small-caps
}
<div id="links" class="right" style="margin-right:65px">
  <ul class="nobull" style="margin:0">
    <li><a href="http://com">This link</a>
    </li>
  </ul>
</div>

关于css - 带有 id 和 css 的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35364891/

相关文章:

html - 三级菜单未显示在带有 css 的正确位置

html - CSS 链接 :hover style only applies to the first instance even with using class

javascript - 如何才能只在系统浏览器而不是 NW.js 浏览器窗口中打开*某些*链接?

jquery - 如何避免爬虫跟随 anchor 空链接(使用 jquery 操作)

coldfusion - 使用 ColdFusion 获取命名 anchor

javascript - 页面从菜单 anchor 滚动到右页,但不是从直接链接

html - 始终在 DIV 内垂直对齐 DIV

jquery - 简单的 CSS/HTML 菜单链接不起作用

javascript - 将代码添加到 Wordpress 站点页面

php - 我如何为从 file_get_content 获得的页面调用 css