Skip to content

Instantly share code, notes, and snippets.

@jlong
Created June 24, 2011 22:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlong/1045839 to your computer and use it in GitHub Desktop.
Save jlong/1045839 to your computer and use it in GitHub Desktop.
3-column grid trick with nth-child clearing for variable height elements
section.three-column-grid {
clear: both;
width: 960px;
@include clearfix;
> section {
float: left;
padding: 0 10px;
width: 300px;
}
// Must have at least IE 9
> section:nth-child(3n+4) {
clear: both;
}
}
@imathis
Copy link

imathis commented Jun 25, 2011

Nice and easy, though a couple of notes.

  1. Semantically a <section> is not the new <div>. The root <section> should be a <div> while the inner sections (if they have headings) are okay.
  2. You could easily drop the presentational classname and use adjacent selectors, or a more appropriate classname, then do this instead:
div.features { @extend .three-column-grid; }

@jlong
Copy link
Author

jlong commented Jun 25, 2011

Can you send me a URL for point number 1?

From A Book Apart's "HTML 5 for Web Designers", Jeremy Keith writes:

"The section element is used for grouping together thematically-related content. That sounds a lot like the div element which is often used as a generic container. The difference is that div has no semantic meaning; it doesn't tell you anything about the content within. The section element on the other hand, is used explicitly for grouping related content."

So it has nothing to do with whether there is a heading inside or not. Headings help create outlines if you have the right tool (I know of none, but that's the idea).

On 2, I can see the advantage, but prefer the more obvious presentational class name.

@imathis
Copy link

imathis commented Jun 25, 2011

  1. http://html5doctor.com/the-section-element/ Look under "rule of thumb"

@jlong
Copy link
Author

jlong commented Jun 25, 2011

Sigh... it is a "rule of thumb"...

But thanks for the criticism. Definitely helps me think better about my HTML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment