views:

201

answers:

2

Newbie question here. I'm in the beginning stages of laying out a site in HTML/CSS based on a sketch I did. So I'm planning my DIVs on the home page and I'm wondering how to name them and which elements should have their own containers. So far, I have the following :

  • container (contains everything on the page)
  • header (will contain the logo and links, which are sort of connected visually)
  • footer
  • content (this will only contain a widget that plays audio tracks)

Now, I also want, on the right side of my page, in a sidebar of sorts, three other elements:

  • a box containing some headlines/descriptions of an RSS feed from my blog
  • a box containing a few dates of upcoming events
  • a box containing some links to my other sites

I'm looking for opinions as to what is the best (and I guess most "semantic") way of handling the DIVs for those "sidebar" elements. Since my plan is to have those three boxes aligned on top of each other, should I just create one main "sidebar" DIV and then create separate DIVs for each of the elements ("feed-box", "events-box", and "links-box)? Or should there be no "sidebar" DIV (doesn't that imply style/position anyway?), and instead just use the three specific DIVs?

Also, should I give that box that contains the audio widget an id of "content" (even though I know exactly what is going into it) or should it be something like "audio-widget"? (Who knows, maybe a year from now, it will hold some other kind of content instead.)

What do you think is the best practice for this kind of naming? I realize that there is no one correct answer and that it might be pedantic to get too hung up on these names. But the "best" way of handling this is not obvious to me and I would like to be clear from the beginning as to why I'm adopting a given naming convention

Thanks.

+4  A: 

The first question you need to ask is this: is your layout fixed or variable width?

If it's fixed width, the usual practice is to wrap everything in an overall div (usually called "container" or "wrapper"). You have this already.

How you lay out the rest of your divs then affects the order in which they appear in your document (eg using floats tends to "invert" the natural order).

I would probably have something like this:

<div id="container">
  <div id="header"></div>
  <div id="content"></div>
  <div id="sidebar">
    <div id="headlines"></div>
    <div id="events"></div>
    <div id="links"></div>
  </div>
  <div id="footer">
</div>

with rudimentary CSS:

html, body, div { margin: 0; padding: 0; border: 0 none; }
#container { width: 960px; margin: 0 auto; }
#content { width: 760px; float: left; }
#sidebar { width: 200px; float: right; }
#footer { clear: both; }
cletus
+1 for the clean, semantic code and the explanation, but I don't quite agree that 'using floats tends to "invert" the natural order'. It certainly *can* but I wouldn't go so far as to say that it "tends to". A good answer nonetheless.
Andy Ford
A: 

The only correct answer is to use as few containers as possible to get the job done. Then supplying an ID value just remember each ID value must be unique. DO NOT add extra div elements just to have extra naming conventions. A div is a semantic element, whose meaning is a division of a document, that is often abused.