8

I'm trying to create flowing content using CSS columns, but I'm running into the problem where gaps between columns readjust when I resize the browser window horizontally. Is there any way to make the column gaps fixed? It seems like the column-gap CSS property only allows you to set a minimum column gap, and as the viewport is expanded, the gaps increase proportionally.

Here's the CSS I have right now:

column-gap: 5px;
-moz-column-gap: 5px;
-webkit-column-gap: 5px;
column-width: 240px;
-moz-column-width: 240px;
-webkit-column-width: 240px;

and then I have divs inside that are fixed width and have display: inline-block.

EDIT: Here's a sample jsFiddle with the appropriate HTML/CSS: http://jsfiddle.net/4cqbr/1/. I'm trying to create a sideways-scrolling collection of posts that are fixed width, variable height. When you resize the 'Result' area, you can see that the column gap expands and contracts.

2
  • 2
    Post a link to your site or Full Source code. Commented Feb 2, 2012 at 0:29
  • You can now accomplish this using CSS grid, see answer here. Commented Jan 7, 2021 at 0:32

1 Answer 1

4

The column gap is only changing sizes because you set a hard width on the columns. You can't have a fluid layout with all hard set widths, something has to be fluid.

Here is an example with fluid columns and consistent gaps.

p{
  column-width: 240px;
  column-gap: 2em;            
  padding: 5px; 
  text-align:justify;
}
Sign up to request clarification or add additional context in comments.

2 Comments

I don't get why it shouldn't be possbile. With the height, gap and column width fixed, there is still the total width of all columns needed flexible. Maybe one ahs to scroll, but that's what I would expect from what Adi tried to do.
Right, instead of adding more column gap space, it should just left-align the columns instead of "justfying" them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.