CSS a href 样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5856451/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:26:50  来源:igfitidea点击:

CSS a href styling

css

提问by Joper

i have a href with class="button"

我有一个href class="button"

I am trying to style this like that:

我试图这样设计:

.button a:link {text-decoration: none} 
.button a:visited {text-decoration: none} 
.button a:active {text-decoration: none} 
.button a:hover {text-decoration: none; background-color:yellow;color:blue}

why it is not working? how to set stye for a href with that class (class="button")

为什么它不起作用?如何为该类的 href 设置 stye ( class="button")

回答by SLaks

.button ais a descendant selector. It matches all <a>tags that are descendants of.button.

.button a是一个后代选择器。这一切都匹配<a>是标签的后裔.button

You need to write a.button:linkto match tags that are both <a>and .button.

您需要写入a.button:link以匹配同时为<a>和 的标签.button

回答by tere?ko

.button a{}is a rule for

.button a{}是一个规则

<something class="button">
   <a href="">foobar</a>
</something>

a.button{}is a rule for

a.button{}是一个规则

<a href="" class="button">foobar</a>

回答by naiquevin

please share the html markup as well.

也请分享 html 标记。

is buttonthe class attribute of the anchor element or is the a tag a child of an element with class button?

button锚元素的 class 属性还是 a 标签是具有 class 的元素的子元素button

if its the former case, use

如果是前一种情况,请使用

a.button:link { }etc

a.button:link { }等等

if its the later, your code is correct

如果是后者,则您的代码是正确的

回答by Sebastian

a.button:link {text-decoration: none} 
a.button:visited {text-decoration: none} 
a.button:active {text-decoration: none} 
a.button:hover {text-decoration: none; background-color:yellow;color:blue}

回答by Quentin

Because you have said:

因为你说过:

"An aelement with the pseudo-class :blahthat is a descendentof any element"

a具有伪类的元素:blah是任何元素的后代

You want:

你要:

a.button:link { /* etc */