Jump to content

Css Syntax


Darwyn
 Share

Recommended Posts

They are identical. I like the longer version because it helps me remember what an id is referring to. And since the second is more specific than the first, if you ever got in a situation where one combination of selectors was overriding another, the more specific one would win. That doesn't come up unless you're using a lot of CSS.

Edited by Deirdre's Dad
Link to comment
Share on other sites

# declares a unique ID. By setting div#menu, it will only effect a div with that id, where as menu alone could be applied to any singular element with that ID.I think...

Link to comment
Share on other sites

If, for some reason, the stylesheet would be applied to some pages with divisions identified with "menu", and other pages with other elements identified with "menu", then you could use the more specific selectors to define differing behavior. You can't have two elements with the same ID on a single page, however.

div#menu {	margin-left:0px;}ul#menu {	margin-left:10px;}

Also, the div#menu selector has a higher precedence, because it is more specific.

div#menu {	color:green;}#menu {	color:red;}/* the color of <div id="menu"> is now green */

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...