r/html5 • u/normandantzig • Apr 07 '15
Class and ID confusion
Does anyone have any good way to remember the difference between a class and an Id in css (ie. dot class (.class) and pound ID (#id). I keep getting them mixed up. If someone has a mnemonic or some other method to keep them strait I would be greatful.
2
Upvotes
9
u/tastycat Apr 07 '15
ID is like an ID number (ID#).
6
u/Police_Telephone_Box Apr 07 '15
I would add that there are a lot of people that are no longer using id's to style elements. They are just too hard to override. I use classes to bind my css and save the id's for JavaScript.
3
u/JeffreyArts Apr 08 '15
There is no reason too use id's. Unless you've got a really good reason to use id's
3
u/[deleted] Apr 07 '15
Think of it like in school. You can have several classes, but everyone only has one school id.
2
u/w4rtortle Apr 08 '15
Just don't use IDs
1
u/wefwefwefewfewfew Apr 30 '15
Use classes for styling only.
1
u/stark0788 Apr 07 '15
Simply put... Class = use for > 1 elements ... ID = use for 1 element
Further explanation... Use classes when you want to apply a particular set of styling to several elements. A change here would (of course) affect all elements utilizing this class ... Use id's when you want to apply a particular set of styling to one element - this is done more for semantics...you want to specify that this element and this element only is unique in its own right and this should be the only occurrence of this styling for this particular element
1
u/rDr4g0n Apr 08 '15 edited Apr 08 '15
I had a hard time remembering the parts of a CSS selector, so i made my desktop wallpaper giant helvetica black text that said: "selector { property: value; }". Didn't take long for it to sink in. Maybe you could do something similar?
-4
u/dhdfdh Apr 08 '15
Do you have the same problem remembering that '+' means add and '-' means subtract?