6 ms·
Not really, the CSS might be organized, but overall it's pretty terrible. Classes are for multiple instances and IDs are for unique instances.
by nudetayne 13y ago
Not really, the CSS might be organized, but overall it's pretty terrible. Classes are for multiple instances and IDs are for unique instances.
- pattle 13y agoI decided to use classes rather than id's because I knew my project page would have multiple characters on it. So I didn't want to have multiple elements with an id of "left-eye" or "nose" etc. But I guess I could have prefixed everything with the characters name and used ID's instead.
- nudetayne 13y agoFrom what I see in the CSS files, you already prefixed (edit: by prefixed, I mean child selectors) everything with the character's name, which is where my confusion comes from. Either everything should use class selectors, or characters should use a class selector and the constituent body parts should be ID selectors.
- sbarre 13y agobut then wouldn't document.getElementById() calls get confused, even though your IDs are nested? Shouldn't it be the other way around? #homer .left-eye { ... } #bart .left-eye { ... } makes more sense to me than .homer #left-eye { ... } .bart #left-eye { ... }
- nudetayne 13y agoThe calls to JavaScript functions that are ID-based would certainly not work. But there are many ways to access them that wouldn't. In regard to the selector type, does Homer have more than one left eye? More than likely not, but that's why I suggested using all class selectors as an option. Using all class selectors would enable you to produce (a) as many Homers as you'd like and (b) as many left eyes, right eyes, mouths, etc as you'd like.
- rimantas 13y ago.homer #left-eye This indeed makes (almost) no sense. It makes no sense for sure if you intend to have several characters on the page — id must be unique, and it does not matter that something is in front of it. .some-class #some-id makes sense only if you want to style page-unique elements differently in some cases but even in that case I'd argue that #some-page-id #some-id would be better (assuming #some-page-id is the body element id).
- robmcm 13y agoYou shouldn't use ID's for any of them. ID's are anchors and should really be reserved for page layout.
- marrs 13y agoMixing classes and IDs in CSS selectors causes headaches at scale because IDs change the order of precedence. These days I just avoid using them in CSS altogether.