Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With column-count, can you dynamically change from 3 to 2 columns if the resolution smaller?

I'm using the column-count property to set a page with multiple divs at three columns, which looks great on larger screens. Each div has a fixed width of, say, 500px (contained images).

When working on smaller screens however, the browser tries to force the content within the original \three columns when it should go to two columns. Is there a preferred best method to have the content go to two columns when the content starts to overlap?

like image 629
natsturner Avatar asked Oct 08 '13 17:10

natsturner


People also ask

What is column-gap?

The column-gap CSS property sets the size of the gap (gutter) between an element's columns.

What are the CSS properties that are used to manage column breaks?

The break-inside property specifies whether or not a page break, column break, or region break should occur inside the specified element. The break-inside property extends then CSS2 page-break-inside property.


2 Answers

If you use the column-width property, rather than column-count, the browser will automatically adjust the number of columns as needed to fill the available space.

http://codepen.io/cimmanon/pen/CcGlE

.foo {
    columns: 500px; // shorthand, prefixes may be necessary
}
like image 111
cimmanon Avatar answered Sep 23 '22 04:09

cimmanon


@media (max-width: 500px) {
  .your element selector here {
 -webkit-column-count: 2;
  -moz-column-count:    2;
  column-count:         2;

  }
}
like image 42
Paulie_D Avatar answered Sep 20 '22 04:09

Paulie_D