Applying styles to only elements within another element

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Applying styles to only elements within another element

Post by alex.barylski »

Code: Select all

#spectra {  /* Apply CSS to a DIV */} #spectra a {  /* Apply CSS to a anchors within DIV with ID spectra */}
This is how I have it now unfortnately the CSS for anchors is also being applied to other anchors not just those within #spectra DIV???

How do apply styles to only the anchors within my DIV?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Applying styles to only elements within another element

Post by Eran »

Your syntax is correct. Make sure: you have correctly closed the spectra div and that the identifier doesn't repeat in the document. Other than that it should work..
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Applying styles to only elements within another element

Post by alex.barylski »

1. Check
2. Check

But the anchors in a menu are still being styled according to what is only supposed to be applied to anchor's inside <div id="spectra">

:(

I thought I had to do something like:

Code: Select all

#spectra > a {
 
}
What is the difference when using the above syntax and what I did earlier?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Applying styles to only elements within another element

Post by Eran »

div#spectra > a will apply only to anchor elements which are direct decendants of the #spectra div. IE6 by the way doesn't recognize this format.

You might try to reset the styles at the beginning of the stylesheet, giving default to the a in the document and see if it works.

Code: Select all

 
a {
      color:#000;
      text-decoration:underline;
}
 
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Applying styles to only elements within another element

Post by alex.barylski »

You might try to reset the styles at the beginning of the stylesheet, giving default to the a in the document and see if it works.
Good idea...thanks :)
Post Reply