PDA

View Full Version : CSS file


scottjohnson
09-08-2006, 11:31 PM
In a CSS file such as test.css, sometimes I see the selectors are prefixed with a '#', or a '*', what do they mean?


#pagebody {
margin: 10px;
}

#instructions{
padding: 2px 8px;
border-bottom:1px solid dimgray;
}

#tab{
position:relative;
top:5px;
left:5px;
}


* html input{
padding: 2px 0 2px 3px; /* starHTMLhack--IEonly (+4px padding needed to match height of select when input{border:1px} */
}



Thanks

mark87
09-08-2006, 11:34 PM
* is a universal selector, normally it is used to specify a style for every element... but used in the context above (* html) it allows only IE to use that style.

# is for the element of that ID. eg. <div id="box"> , #box { }.

A preceding dot (.) is for classes.

scottjohnson
09-08-2006, 11:54 PM
Thanks for the response.

Just between the '.' and '#'.

Why to use the # (for an ID), while not use the class=?

I mean, I could use:

<div class="box"> , box { }.

instead of <div id="box"> , #box { }.

I just wonder why. There must be some unique reason.


Thanks.

mark87
09-09-2006, 12:00 AM
Classes can be used more than once, ID's cannot. Also a style specified by ID will take dominance over a style set by a class (I'm pretty sure).