css - 如何通过定位 anchor 标记内的类来更改 anchor 标记中的颜色或文本?

标签 css

有人可以解释为什么会发生以下情况吗:

<a href="#" class="test">Test</a>

<style type="text/css">
.test {
border: thin solid blue;
color: red;
}
</style>

这只会创建边框,但不会在使用类时将文本变为红色。

但是,这可以在使用 id 时将文本变为红色:

<a href="#" id="test">Test</a>

<style type="text/css">
#test {
border: thin solid blue;
color: red;
}
</style>

为什么类不改变文本颜色,而使用 id 却有效?

谢谢!

最佳答案

用这个

demo here

 <a href="#" class="test">Test</a>

 <style type="text/css">
a.test {
border: thin solid blue;
color: red;
}
</style>

关于css - 如何通过定位 anchor 标记内的类来更改 anchor 标记中的颜色或文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13870009/

相关文章:

css - 透明 Div 后面的可点击图像映射 - 在 IE 中工作

html - CSS布局不在同一个位置

css - 苹果设备会忽略 CSS @viewport 定义吗?

javascript - 将 CSS3 matrix3D 绘制到 Canvas 2D 元素

css - 在表格内垂直对齐

html - CSS背景图片有问题

javascript - 如何将这个球附加到光标上?

css - 如何使 bootstrap3 类与打印兼容

html - 将 div 元素固定到页面缩放时的位置,而不是滚动时

css - z-index 属性不会导致 IE8 中的重叠