Steven Matthews
Steven Matthews

Reputation: 11355

Styling elements under a given Id

So I have this div called top nav, i.e.:

<div id="topnav">

And I would like to style all of the A elements under this div, however NOT the A elements outside of this div.

How would I go about that in CSS?

Upvotes: 0

Views: 72

Answers (4)

MCSI
MCSI

Reputation: 2904

if you want this to all the elements inside the div, it must be...

jquery

$('#topnav a').css('color', 'red')

css

#topnav a {
color:red;
}

Upvotes: 0

Andy E
Andy E

Reputation: 344803

Specify a as a descendant of #topnav in the selector:

#topnav a {
    /* styles */
}

See http://www.w3.org/TR/CSS2/selector.html#descendant-selectors.

Upvotes: 5

Matteo Mosca
Matteo Mosca

Reputation: 7458

I'd say a simple #topnav a selector would do.

Edit: sorry I misread. I thought you wanted to style all the elements under it, not just the <a> elements. Fixed.

Upvotes: 1

Simone
Simone

Reputation: 21292

#topnav a { /* write here your CSS rules */ }

Upvotes: 1

Related Questions