30

I was today years old when I discovered the CSS property column-count.

Do you have any fucking idea how many times I’ve used CSS grid or flex box or BOTH when all I wanted was to make a layout with a set number of columns?

Why the fuck didn’t I know about this thing?

Did you know about this thing?

Comments
  • 6
    The hell kinda black magic is this property?
  • 5
    @N00bPancakes RIGHT? It’s even pretty well-supported! 0.0
  • 4
    Holy shit, this is pretty cool. There's even a column-span property to make something span across multiple columns.
  • 3
    There is always some weird ass CSS property that solved any problem you might have had that shows up late. No one really knows CSS to its full extent
  • 12
    It’s a hidden gem
    column-count
    column-gap
    column-width

    Here’s a pro tip too:
    I used to avoid columns because child-elements can be chopped up into 2 cols in an ugly way

    But all you gotta do to avoid that is to add this to the child-element:

    break-inside: avoid-column;
  • 6
    Pros and Cons
    + great for ”masonry layouts”
    - no good if you need items of various heights to align into rows
    - you cannot control which column empty space ends up in (as you sort of can with flex) as far as i know.
    + there is a column-gap property
    - there is no row-gap property (the concept of rows doesn’t even exist here)
    - by default child items can wrap over multiple columns (without the tip I showed in my last post, or if they are inline-block)
  • 1
    @jiraTicket CSS is a cruel mistress with how many situations there are for "you can control gaps... well the col gap... not row gaps..."

    Does everything have to be one step forward, one step back!?!?!!?
  • 0
    This is gonna be great next time I need to work on front end. I'm totally going to forget everything said in this thread.
  • 1
    Good old <table> comes back to life in a different form
  • 0
    Hasn't this been around since the beginning of CSS 3? It's my go to "quick columns" setting for chunks of text. (Beyond that I don't tend to faff too much though, tend to use flexbox for more control.)
  • 2
    @AlmondSauce Yeah! That’s part of the reason I’m pissed I didn’t know it.
  • 0
    @N00bPancakes but a row gap property doesn't even make sense here... The elements just sorta "flow" through the columns. If you need a row gap property you're probably using this wrong and should instead use a grid.
  • 0
    I have always used flex for pretty much everything, even though I was aware of the grid and the column properties. I should start using those!!
  • 1
    @inhamul The biggest downside I used to see with Flex for column layouts is that you can’t just style the parent to decide the gaps between child-items.

    So much nicer to just have child-items remain unchanged and only style the parent to decide how they should be placed. As you can with grid.

    But now with the property row-gap gaining support it is possible. (Still no safarisupport though, according to mdn)
  • 1
    Tables... this is tables.

    We’ve come full circle.
  • 0
    What the actual fuck. Why couldn't those dumb cunts spewing medium articles write about this shit instead of that 998th article on react.
  • 0
    @hashedram Probably some variation on “this is easy, everyone else probably knows about it, no one cares”
Add Comment