The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS #id.class or #id .class Re: #id.class or #id .class


you wouldnt use an id and a class for hooking onto the same element. that would look like this and is wrong: #id.class

but what you are asking is when to use the certain selectors.
you can have

im a message

now to hook onto that you would go: div.message – correct

or if it had a id instead of class:

im a message

div#message – correct

you can also have


now, to hook on or style this div you can only use one class, or one id per set of style rules

like this:
#message{color: red;}
.box{font-size: 14px;}
but not{…}

and for the last bit

something like this: #message .title{..}
this is when there is another element with the class of title is inside the element with an id of message. that would look like this

Im some random title

i hope this helps you understand better