tailwindcss icon indicating copy to clipboard operation
tailwindcss copied to clipboard

`column-count` support

Open LoganDark opened this issue 8 years ago • 15 comments

I'd appreciate Tailwind utilities for working with the column-count property.

Something like .col-count-2, or something similar.

It's great for masonry layouts:

image

(image source)

LoganDark avatar Aug 23 '18 06:08 LoganDark

+1 to this. I just tweeted tailwindcss before coming here asking if it was something planned.

I'd be willing to take a stab at it, if it's wanted in core at all. If not I will look at making a plugin.

codytooker avatar Aug 23 '18 20:08 codytooker

I think the css column spec would be a good addition to the framework. Even if it is set to false by default since it is a less commonly used system.

column-count:
column-gap:
column-span:
column-rule:
column-width:

My only thought is it may produce some naming conflicts with grid-column once those get added to core depending on how they are named. But that could be discussed and figured out.

Also since these selectors are seldom used the module / modules could be set to false in the default config if need be.

codytooker avatar Aug 24 '18 14:08 codytooker

I submitted a pull requests that is a sort of work in progress brainstorming section for the css column specification, it can be found at #541 . If anyone has some insight in how it should be handled, head over there and leave a comment.

codytooker avatar Aug 29 '18 19:08 codytooker

column-count:
column-gap:
column-span:
column-rule:
column-width:

@codytooker

.col-count
.col-gap
.col-span
.col-rule
.col-w

:)

LoganDark avatar Aug 29 '18 20:08 LoganDark

@LoganDark take a look at #541 if you look at the file changes you can see the selectors I came up with. I was trying to model most of it after the way borders are handled currently in Tailwind.

For instance Column Fill classes are the following.

.column-fill
.column-balance
.column-balance-all

And Column Rule style classes are

.column-solid
.column-dashed
.column-dotted
.column-none

With column rule color and column count following the same convention with

.column-{color}
.column-{number}

I do like the short hand .col but was concerned with how the grid implementation that I assume is coming to tailwind will be built.

codytooker avatar Aug 29 '18 20:08 codytooker

@codytooker you really should use plain col.

https://tailwindcss.com/docs/flexbox-direction/#class-reference

That's the convention these guys use, and col is much more convenient and easy to type than column.

I'm pretty sure they'll use a grid prefix for CSS grid.

LoganDark avatar Aug 29 '18 20:08 LoganDark

Updated classes to use .col- instead of .column- in agreement with @LoganDark 's input. changes can be seen at #541

codytooker avatar Aug 31 '18 03:08 codytooker

Hey there! In my opinion this should not be a part of core yet (not even disabled by default) but that doesn't mean it's something we don't need.

I've published a couple of plugins to NPM that would do the exact same thing your PR does plus some extra utilities related to CSS multi-columns (I've actually incorporated some of the naming conventions you discussed to what I already had before publishing).

Let me know if there's anything else you're missing here, feel free to open issues to discuss whatever and let's wait on Adam's input on this (guessing he'll pass on the PR since this is what the plugins API was built for).

  • Break: https://www.npmjs.com/package/tailwindcss-break
  • Multi-Column: https://www.npmjs.com/package/tailwindcss-multi-column

hacknug avatar Aug 31 '18 14:08 hacknug

I think this would be better as a plugin at least for now, always can revisit later though.

"Rule #1 of open-source: no is temporary, yes is forever."

adamwathan avatar Mar 18 '19 17:03 adamwathan

Can revisit this now as a JIT plugin?

surjithctly avatar Jun 25 '21 13:06 surjithctly

Yes, this would be great. It cannot be recreated with other classes.

michalhudecek avatar Aug 27 '21 14:08 michalhudecek

+1

nimajn-eb avatar Apr 11 '22 17:04 nimajn-eb

If you're planning to use this in ul element, Columns work just fine.

disemio avatar Jul 12 '22 08:07 disemio

For those who need this in Tailwind v4, here's what I came up with while migrating from tailwindcss-multi-column: https://play.tailwindcss.com/lC8MBCSicQ?file=css

@import "tailwindcss";

:root{
  --tw-column-rule-style: solid;
}

@theme {
  --column-rule-style-solid: solid;
  --column-rule-style-dashed: dashed;
  --column-rule-style-dotted: dotted;
  --column-rule-style-double: double;
  --column-rule-style-none: none;
  --column-fill-auto: auto;
  --column-fill-balance: balance;
  --column-fill-all: all;
  --column-count-span-none: none;
  --column-count-span-all: all;
}
@utility col-count-*{
  column-count: --value(integer);
}
@utility col-gap-*{
  column-gap: --spacing(--value(integer));
}
@utility col-w-*{
  column-width: --spacing(--value(integer));
}
@utility col-rule-*{
  column-rule-style: var(--tw-column-rule-style);
  column-rule-color: --value(--color);
  column-rule-width: calc(--value(integer) * 1px);
  column-rule-style: --value(--column-rule-style-*);
}
@utility col-fill-*{
  column-fill: --value(--column-fill-*);
}

/* Specific name with "col-count" prefix to avoid collision with grid-column utilities */
@utility col-span-*{
  column-span: --value(--column-count-span-*);
}

The col-gap and col-w utilities are using a soon-to-be-added special function "--spacing()" so it's currently working only on the insiders release of Tailwind, but it's already merged so it's coming soon. You can read more about it here.

** edit: --spacing() function was released already, my bad. The PR is just about displaying the suggestions!

davidwebca avatar Mar 27 '25 20:03 davidwebca

Unless I'm blind, columns- is currently laying items in a vertical order.

Is there a plugin to achieve masonry but with horizontal ordering ?

so instead of

1 5
2 6
3 
4

it's

1 2 3
4 5 ...

benjyAuthi avatar Apr 14 '26 01:04 benjyAuthi