I'm trying to work out how I can make my CSS as de-coupled from my HTML as possible. The way to do that would be to write the basic layout elements in the HTML in a standard way, so that different CSS files could know exactly what the mark-up it's working with will look like without having seen it.

So I was wondering if there exist anywhere a set of standards for how you should name your layout elements and what order to put them in. E.g. a sensible way to mark-up my page would be as follows (note that I'm using HTML5 elements and following the theory that you should never use IDs for CSS rules):

<body>
  <div class="container"> <!-- central "squeeze" for the content -->
    <header>
      <img class="logo" />
      <nav class="primary"></nav> <!-- main navigation -->
    </header>
    <aside class="pre"></aside> <!-- left column -->
    <article class="main"></article> <!-- central main content -->
    <aside class="post"></aside> <!-- right column -->
  </div>
</body>

Many pages use something similar to this basic layout. But as you can see, the name of the "container" or "primary" class will vary a lot, as will the use of <aside> for columns. Also, there are probably variances in ordering, like some people would put the <nav> element after the <header> rather than inside it, or the column elements inside the <article> element.

Does anyone know of any work that's been done to standardise the ordering and naming of these commonly used layout elements? Like a microformat or something?

有帮助吗?

解决方案

I don't think there is an absolute standard, since no two websites are the same.

Allright, some are, but that's not the point. :)

Anyway, since the CSS is made specifically to markup that single website, you can't actually decouple it in such detail. You won't find some ready made CSS sheets that you can just plugin your website to place all those navigation containers.

I think the best way is to come up with a standard for yourself and stick to it. I hope you would be able to find better names than the often used but quite abstract 'container'. And maybe, some day, it will become the defacto standard.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top