如何设置某个div内的所有锚标签?

时间:2022-10-31 18:37:58

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:

我正在使用它来设置#content div中所有标签的样式。但是,问题是它似乎没有在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开始递归应用?我想我正在寻找排序的通配符值?

4 个解决方案

#1


34  

You made it much more complicated than it needs to be:

你使它变得比它需要的复杂得多:

#content a {}

#2


5  

#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}

#3


1  

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!

希望这有帮助!

#4


0  

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

#1


34  

You made it much more complicated than it needs to be:

你使它变得比它需要的复杂得多:

#content a {}

#2


5  

#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}

#3


1  

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!

希望这有帮助!

#4


0  

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