Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tailwind Columns Cutting Off + Setting Height

I’m trying to create a masonry grid exactly how it’s showcased on the Tailwind documentation: https://tailwindcss.com/docs/columns#basic-usage

So, I have the following code trying to achieve that:

const Tile = (props) => {
  const { data } = props;

  return (
    <div className='rounded border p-4 mb-4'>
      {data}
    </div>
  );
};

const Masonry = (props) => {
  const { data } = props;

  <div className='columns-3'>
    {data.map((item) => (
      <Tile
        key={item.name}
        data={item}
      />
    ))}
  </div>
};

However, for some reason, the content is being cut off like so, and I haven’t been able to figure out why. I’ve checked the dev tools, tried setting custom heights to the entire container, to the specific container where columns-3 is defined, and nothing is working.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

cut off grid

What am I doing wrong?

>Solution :

Apply break-inside: avoid-column or break-inside: avoid with break-inside-avoid-column or break-inside-avoid respectively to the <Tile> root <div> to avoid the behavior you describe:

<script src="https://cdn.tailwindcss.com"></script>

<div class="columns-3">
  <div class="rounded border p-4 mb-4 break-inside-avoid-column">
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
  </div>
  <div class="rounded border p-4 mb-4 break-inside-avoid-column">
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
  </div>
  <div class="rounded border p-4 mb-4 break-inside-avoid-column">
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
  </div>
  <div class="rounded border p-4 mb-4 break-inside-avoid-column">
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
  </div>
  <div class="rounded border p-4 mb-4 break-inside-avoid-column">
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
  </div>
  <div class="rounded border p-4 mb-4 break-inside-avoid-column">
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
  </div>
  <div class="rounded border p-4 mb-4 break-inside-avoid-column">
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
    Foo bar<br/>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading