Html 如何在某个 div 内设置所有锚标签的样式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14572100/
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
How do I style all anchor tags inside a certain div?
提问by Propeller
I can't figure out how to properly do this. I have the following CSS:
我不知道如何正确地做到这一点。我有以下 CSS:
#container > #main > #content > a {
color: #3B7315;
}
I'm using that to supposedly style all <a>
tags in the #content
div. The problem is, however, it doesn't seem to style <a>
tags inside divs or nested lists, etc. It only styles the top-most tags such as the following:
我正在使用它来<a>
设置#content
div 中所有标签的样式。然而,问题是,它似乎没有为<a>
div 或嵌套列表等中的标签设置样式。它只设置最顶层标签的样式,如下所示:
<div id="content">
<a href="#">Lorem ipsum</a>
</div>
When I put the link inside another element, the styling is gone.
当我将链接放在另一个元素中时,样式就消失了。
So how do I include the whole sub elements and make the style recursively apply itself from #content
onwards? I think I'm looking for a wildcard value of sort?
那么我如何包含整个子元素并使样式从#content
以后递归地应用它自己呢?我想我正在寻找某种通配符值?
回答by John Conde
You made it much more complicated than it needs to be:
你让它变得比它需要的复杂得多:
#content a {}
回答by Milche Patern
#content a, #content a:link, #content a:visited {base style rules}
#content a:hover, #content a:visited:hover, #content a:active {over style rules}
#content a:focus {wai style rules}
回答by Eric Diviney
All that is necessary is the container and its anchors you are trying to style. The following should work fine, especially if that div you are using is an id, because then it wont be repeated onto other elements, as it would if you had a class on that div and other divs.
所需要的只是您尝试设置样式的容器及其锚点。以下应该可以正常工作,特别是如果您使用的那个 div 是一个 id,因为这样它就不会重复到其他元素上,就像您在该 div 和其他 div 上有一个类一样。
#content a{ style rules; }
Hope this helped!
希望这有帮助!
回答by nexus_07
the symbol > is only applies to the direct child..that's why if you use that it would be only applied to the first child a of the element id content
符号 > 仅适用于直接子级..这就是为什么如果您使用它,它将仅适用于元素 id 内容的第一个子级 a