#id vs. div#id ?

liunx

Guest
Hello everyone,
Can someone point out the difference between #id and div#id? I've notice some css that has div#id and some site don't. Is it an inherit rule? I'm sorry but I just don't have the time to go through all the CSS rules. OK.. I'm just lazy but I will if I have to.

Thanks,
EugeneNo real difference if the id is used on a div. But a div#id can only be used on a div, a #id may be used for other stuff.The shorter format probably has more use with classes ("div.class" vs. ".class") since a class could logically be applied to more than one type of HTML element, whereas an ID should always be used only once within your HTML, and thus should always apply to just one element type.

However, I tend to use the "#id" format a lot, I guess because I'm lazy and want to type fewer characters, plus there's less to change if I decide to change the type of HTML element for that item in my markup. (For instance, I realize I don't need it to be a DIV, it can just be a H1 element.)Thank you both.. I've tested it and now I understand.

I tend to use .class more then #id also but that's just the way I'd started learning css and now I'm trying to learn all the rules so I can correct the mistakes I've made. Or rather to be validated.

Have a good day..
Eugene
 
Back
Top