# Wednesday, 18 January 2012
« CSS 3 new column module | Main | Goodbye Internet Explorer 6 »

In a former post I already presented the new CSS 3 column module and some funky stuff one can do with it.

However sometimes you want to provide your end users the possibility to decide for themselves how many columns they want to see. The following sample will do just that with the help of some javascript and the new HTML 5 range input type.

The following CSS is used to style up some range of text from the beginning:

#test {
    column-count: 3;
    column-rule:2px solid #000;

to style up a div element with id test:

<h3>How many columns?</h3>
<input type="range" min="1" max="5" onchange="changeColumnCount(this)">
<div id="test">
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla dignissim mattis justo, 
      sit amet volutpat turpis convallis vel. Etiam pulvinar tincidunt diam, sit amet ornare justo

Note the type of the input element: range. I specified the min and max values so there can be only one column or a maximum of five columns. The onchange event will call the following javascript function which takes care of the behavior part and makes the magic happen:

<script type="text/javascript">
    function changeColumnCount(meter) {

        document.getElementById('test').style.columnCount = meter.value;


The meter value gets set to the column-count CSS property. Notice the way it is done in javascript, not via column-count but via the element’s property style.columnCount. Make sure that you have the casing right as javascript is a case sensitive language!

I used Internet Explorer 10 on Windows 8 and Opera on Windows 7 to test the feature:



The second IE10 is the Metro version. Note the number 4 coming over the meter. This shows up when dragging the slider from one value to another and disappears again when you release the slider.

The full code to test this out:

Have fun with this!

Grz, Kris.

CSS3 | HTML5 | range
Wednesday, 18 January 2012 12:41:22 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |