css - 'a:link {color}' CSS 选择器的问题
问题描述
我想更改页面上所有链接的颜色,但它不能在 chrome 上工作,在 Opera 上工作正常。我不明白发生了什么你能帮我让它在每个浏览器上都能正常工作吗?
a:link
{
color: rgb(255, 169, 73);
text-decoration: none;
}
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Lake Towada</title>
<link rel="stylesheet" href="CSS/style.css">
</head>
<body>
<p>
some text<a href="https://www.japan-guide.com/e/e3775.html" target="-_blank">Oirase</a>
some text<a href="https://www.japan-guide.com/e/e3780.html" target="-_blank">the mountains</a>some more text
</p>
</body>
解决方案
样式化锚链接可能有点棘手。有几个伪类以及基本a
标签选择器可用于根据状态影响链接的样式。
/* newly added in the CSS selectors Level 4 specification */
:any-link, p :any-link{
color:black;
}
/* it is recommended to always have the pseudo classes it in this order */
:link{
color:blue;
}
:visited{
color:mediumvioletred;
}
:hover{
color:mediumaquamarine;
}
:active{
color:green;
}
/* lowest specificity, so it will not be applied */
a{
color:green;
}
<div><a href="#">This link starts out blue.</a></div>
<div><a href="https://www.google.com/">This link *might* be violetred in your browser.</a></div>
<div><a href="https://www.facebook.com/">So might this.</a></div>
<div class="special"><a href="#">Hovering will turn the links aquamarine.</a></div>
<p><a href="#">This link is black in browsers that support the new pseudo class. It also won't have any hover effects.</a></p>
如果您曾经在 Chrome 浏览器(但不是 Opera)上访问过代码片段中的某个链接,它将具有不同的颜色。
我提供的代码片段中的一两个链接很可能已经为您提供了不同的颜色,因为您过去访问过其中一个网站。
要获得一致的结果,请明确设置:link
和:visited
并注意选择器特异性。
您可以使用它:any-link
来获得一致的结果,这实际上:link,:visited
与代码片段中的规则仅适用于最后一个链接)。
推荐阅读
- python - 从任务管理器创建计划任务
- string - 在prolog中获取两个字符串的最后一个字母
- python - 在饱和度不均匀的图像中渲染文本
- python - Python gekko 找不到“options.json”文件
- python - 如何从 html、json 中提取标签?
- python - 使用python open cv(ORB)进行图像比较
- powerbi - Power BI:使用卡片显示总计的百分比
- python - 向numpy数组添加维度
- css - select2 选项显示在错误的位置
- swiftui - 如何从 AppDelegate 调用 ViewModel 中的方法