Subscribe by Email

Put simply, CSS3 regions associate boxes and blocks with other blocks to allow a designer to make content flow from one box into another automatically. Previously this was impossible with just CSS. The CSS3 Regions Specification expands CSS further from a static design to a more responsive and future proof language.

This article is about new CSS which may not be supported in every browser! Be careful.

What are regions

Put simply, regions are a way in CSS to allow content to flow from one box to another. This tutorial will show you how regions work according to the current specification. Currently regions are available in the nightly build of webkit and in the platform preview of IE.

Enabling Regions

We’re going to be using Google Chrome as the web browser of choice for this tutorial as it has the greatest support for this feature. For some odd reason Chrome has regions disabled, so we need to go and enable it by going to chrome://flags

How it works

Effectively there are two key properties to a region flow. Those are the flow-in and flow-out. Now pay attention, because this can be a little tricky to wrap your head around. The basic principle is that we can allow content to flow from one block to another. The content of a specified div will go from one div to the other, ‘flowing’ between them, rather than having to put specific content in each div separately.

The idea is that we will have one block which contains the content, and ‘flow’ the content from that block into several other blocks. The content will still be contained within the primary container physically, but it will be diverted to flow through other block elements.

Keywords

For a flow to work we give it a keyword. A keyword identifies which items will flow into which containers. So suppose we have something like this in HTML:

We can set it up so the article source will ‘flow’ into the regions. Note that the source div will effectively disappear since the content will be moved into the regions. For this particular example we’ll use the keyword ‘main’. You can use any keyword you want, it doesn’t really matter. Just make sure the content and the objects you want the content to flow into use the same keyword.

So the content will flow into this hypothetical ‘main’ container and then flow out again into the regions. Although this isn’t necessarily completely accurate it is an easy way to think about it.

You can have multiple things flowing into one container. They will appear one after the other in the flow. So you could have two sources, or other content which will be added on to the flow.

Styling the flow

It becomes very easy to style the flow containers with the @region tag. All you need to do is target the element and style as you see fit. For example, you can target the HTML in the first region in the code above like so:

@region #region1 {
p { ... }
}

What is the benefit to using this? It means you can style content that passes through multiple regions. You could highlight the first paragraph which may appear in two regions.

An Example

To help show you exactly how this all works, lets try a simple example. We have a layout in HTML like this:

You can put the article in the .source div if you want. Make sure it’s really long! Every .region div represents a single flow of content. That means we’re going to make the content flow from one to the other. Create a CSS file and put the following in it:

The important lines to note are the flow from and flow into lines in .region and #source. The content flows from the source to ‘main’, and then from ‘main’ to the regions. Pretty simple, huh?

Support is currently pretty bad with you needing to enable it in chrome. The platform preview of IE also supports regions, which is a big plus. However, it is totally unrealistic that you would use this in a real life project. It is nice, though, to see what is under development in web design.

Hey Johnny Simpson,
I’ve got a few questions about a project of mine which I was hoping I’d be able to contact you directly about. If you don’t mind could you email me for further discussing.
Thank you very much.
Great site, and thanks for all the help and tutorials.

I just like the helpful information you supply to your articles.
I will bookmark your blog and test once more here regularly.
I am quite certain I will be told many new stuff proper right here!
Good luck for the next!