Jump to content

Css Syntax


Darwyn

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.

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 it was just menu, then couldn't you use it on other elements? I was thinking that div#menu would force the style to a div.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...