More CSS questions

Associate
Joined
19 Oct 2002
Posts
206
Location
Oop north - where it's grim...
Hi All

Let's say I have a CSS with a class ("myclass"), and an ID ("myID"). I want to create rules for links (and only links) that appear in a myclass element, with (and only with) an ID of myID - or to put it another way, I only want the style to apply to links with an id of myID, that appear in elements of the class myclass.

This doesn't seem to work for me:

Code:
.myclass a #myID {
     some rules...
}

Obviously I've got my selectors in a muddle somewhere... where am I going wrong?

TIA

Si.
 
Last edited:
Simebaby said:
Code:
.myclass a #myID {
     some rules...
}
That's looking for an element #myID that is a descendant of an <a> element. Remove the space (a space is a descendant selector), and the rule applies as you need:
Code:
.myclass a#myID {
     some rules...
}
This will only ever apply to one unique link per page, since IDs must only be used once per-page.
Use of the 'a' in the rule is not really necessary unless you've got issues with specifity, .myclass #myID { } will do just as well.
 
This will only ever apply to one unique link per page, since IDs must only be used once per-page

I realised that (some time) after I posted... but left the question as I was curious as to what I was doing wrong.

Thanks for the reply. :)
 
Back
Top Bottom