如何在 CSS 中将颜色设置为用户的链接颜色
How to set the color to the user's link color in CSS?
我想让一个元素使用浏览器默认用于未访问链接的相同颜色。我该怎么做?
<div style="color:???">This should have the same color</div>
<a href=".">as this!</a>
此外,如果可能的话,它也应该在较旧的浏览器中工作。JavaScript是可能的。
你可以
这样做:
var colored = document.getElementsByClassName('colored')[0];
style = window.getComputedStyle( document.querySelector( '.links' ), ':link'),
color = style.getPropertyValue('color');
colored.style.color = color;
a:link{
color: #FF5656;
}
<div class="colored" style="color:???">This should have the same color</div>
<a class="links" href="">as this!</a>
如果我理解正确,像currentColor
这样的东西可以做到这一点,但在这种情况下你需要继承,所以我已经包装了div
并a
currentColor
关键字表示 元素的color
属性。它允许使颜色属性 由属性或子元素属性继承,这些属性不是 默认继承它。它还可用于继承 元素的
color
属性,等效于继承 关键字(如果有)。
片段
#parent {
color: red
}
a:link,.child {
color: currentColor
}
<div id="parent">
<a href="#">This will be red</a>
<div class="child">This will have the same color has the link</div>
</div>
两种简单的方法:
方法一:使用<a>
标签。只需使用 <a>
标签,因为它用于超链接,但没有"href"。 <div>
标记取决于您的程序。
<div><a>This should have the same color</a><div>
<a href="#">as this!</a>
方法2:使用css。
.SameColor {
color: #0000EE;
}
<div class="SameColor">This should have the same</div>
<a href="#">as this!</a>
相关文章:
- 为Fullcalendar中的特定时段设置不同的颜色
- 使用javascript onclick设置CSS颜色
- j查询如何设置/取消设置下拉菜单的背景颜色
- 如何使用chartjs设置条形图中每个条形图的颜色
- 使用JS将页面中的每个字母设置为随机颜色.为什么在页面的每个打开标记之前总是有一组额外的span标记
- Highcharts.js设置用于更改列颜色的阈值
- 如何将字体颜色或背景颜色设置为javascript confim框
- 使用 JS 将图像的特定背景颜色设置为透明
- 如何在 CSS 中将颜色设置为用户的链接颜色
- 将背景颜色设置为SAPUI5中的输入框
- 使用存储的颜色设置ng中的动态背景颜色重复
- 如何将画布背景颜色设置为闪烁'n'秒
- Snap.load()一个svg img并为其填充颜色设置动画's子节点
- 如何将背景颜色设置为具有与url锚相同id的元素
- 我已经将背景颜色设置为白色,但是父元素的不透明度如何影响它
- 如何将Greasemonkey中的字符串颜色设置为红色
- 如何移动谷歌图表的颜色设置从文件到另一个
- 谷歌图表-如何从数据中移动颜色设置
- 将背景颜色设置为范围输入的值
- 将 Mouserover 背景颜色设置为无