Hacker News new | ask | show | jobs
by pattle 4598 days ago
I 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.
2 comments

You shouldn't use ID's for any of them. ID's are anchors and should really be reserved for page layout.
From 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.
but 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 { ... }

  .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).

The 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.