Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I style all anchor tags inside a certain div?

Tags:

html

css

I can't figure out how to properly do this. I have the following 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:

<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?

like image 533
Propeller Avatar asked Jan 28 '13 22:01

Propeller


People also ask

Can you put a style tag inside a div?

The <div> tag can NOT be inside <p> tag, because the paragraph will be broken at the point, where the <div> tag is entered. To apply styles inside a paragraph use <span> tag, which is used with inline elements.

How do you give an anchor tag a style?

CSS Code. When styling the text of the link itself, we simply reference the anchor tag class name only, and we change change things such as the text's color and other attributes. When referencing the special attributes of the anchor tag, such as link, visited, hover, and active.

How do I change the position of an anchor tag in CSS?

You have to give your anchor a the rule display: block; . Anchors are inline elements per default. If you give an element position: absolute , you take it out of so-called normal document flow.


2 Answers

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

#content a {}
like image 170
John Conde Avatar answered Oct 01 '22 07:10

John Conde


#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}
like image 34
Milche Patern Avatar answered Oct 01 '22 08:10

Milche Patern