Using CSS Regions as an Enhancement

If you were not aware of them CSS Regions are proposal to CSS3 that would allow for some magazine like layouts in HTML pages. Adobe has been leading the charge on getting them into WebKit.  They are currently available in Chrome. (Also I think IE10)

Now the way they work:

  • You create a bit of content in an element like an article
  • You designate that article as the source of a “flow”
  • You designate other elements as the recipients of the “flow” (We’ll call them “regions”)

Then when the browser renders the content

  • The element designated as the “flow” is not shown
  • The content of the “flow” pours into the “regions”

Assuming this HTML:

And this CSS:

You get something like this:

I have a demo. It only works in Chrome.  Resize the screen to see the flowing of the content.

I was presenting on them the other night and I got asked a pretty good question.

Have you thought about how these degrade?

I made a bad joke, then mumbled something about if the browser doesn’t support CSS Regions then the original “flow” element gets displayed and all is well.

I tested it today. And all is not well. Because I still created those region elements. And they show up down at the bottom and add whitespace.

Check out the demo on any browser bu Chrome and you’ll see what I’m talking about all the way at the bottom.

So after some experimentation I decided that the best way to handle this was to create my four regions with CSS exactly how I had but only inject the region holders if the browser supports regions, like so:

Here’s a demo of the improved version.

In this case, I get a much better experience for non Chrome users–no weird mile of whitespace at the bottom of the content.

2 thoughts on “Using CSS Regions as an Enhancement

  1. @Terrance:

    I think I’d solve the problem a little different. What I’d do put a class on the “display” div (the wrapper for you region flow) that hides that div by default. Then if the flow is supported, I’d show the div.

    Here’s an example:

    I like this approach better because you don’t have to add nodes to the DOM, you’re just showing the region flow area. I guess I just think it’s simpler.

    The more global approach, would be to add a class to all region flow tags, which sets “display: none”, then update that CSS declaration for browsers that support flow so that it’s shown.


  2. I agree with Dan. Approaching this Modernizr-style and using a class name to detect CSS regions support would be best (hiding it if it didn’t support regions).

    Both solutions require JS, which isn’t perfect, but the class method makes it a bit better as it limits how much you have to change the DOM (if you have a lot of regions).

    I’d also love to see a JS polyfill that performs this functionality for browsers that don’t support the CSS, but it doesn’t seem many are aware of this functionality yet.


Leave a Reply to Dan G. Switzer, II Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s