Colm - Column maker

Colm provides responsive columns (like Pinterest or Masonry) with minimal setup. Supports current version of all major browsers.

For the source code, visit Colm's github repository.

Basic usage

You are done. No other files to import, no javascript to call.

You can now use regular CSS, including @media queries to control the width of your container(s) and hence the actual number and width of columns. When the window is resized, colm checks if the number of column needs to be changed, and if so, lays out the elements again.

How does it look?

Drag the divider to see how items are layed out at various widths, or visit the full-page demo.

You can also use the kitchen sink to try out various settings.

What just happened

Colm scans your HTML for elements containing the data-colm-width attribute, and lays out all their immediate children into the number of columns that best fit the desired column width. This is achieved by placing the appropriate number of simple <div> elements into the container to represent columns, and then looping through all the original children and placing each into the shortest column.

Colm relies on CSS3 flex box functionality. If it is not supported in the browser, Colm will quietly skip layouting and leave your HTML as is.

Advanced usage

colm()

Use colm() to programmatically trigger layouting on the page. This is automatically called on page load and resize.

colm.appendTo(selector,content)

Use colm.appendTo to add new children to a container. Content can be a single element, an array or node list of elements or an HTML string.

data-colm-align-columns="alignment"

Use the data-colm-align-columns attribute on the container element to control distribution of left over space, if the width of the container isn't an exact multiple of the column width. Can have the following values:

data-colm-align-items="alignment"

Use the data-colm-align-columns attribute on the container element to control distribution of left over space within each column. Can have the following values:

data-colm-min-width="width in pixels"

Use the data-colm-min-width attribute on the container element if you want to allow your columns to shrink somewhat to fit another column in the container.

data-colm-place="column"

Use the data-colm-place attribute on child elements to force them into a particular column. Use negative numbers for counting from the right. The most useful values are "1" and "-1", especially when used on the first few children. This can be used to place content reliably in top left and right corners, and gracefully collapse it into a single column on narrower displays.

Things to consider

  #content > [data-colm-column] { 
    border-left: solid 1px silver;
  }
  #content[data-colm-columns="1"] .hide-on-narrow { 
    display:none;
  }
  #content > [data-colm-not-first] { 
    border-left: solid 1px silver;
  }