Tailwind栅格被切断 + 设置高度

huangapple go评论106阅读模式
英文:

Tailwind Columns Cutting Off + Setting Height

问题

我正在尝试创建一个类似于Tailwind文档中展示的瀑布流网格:https://tailwindcss.com/docs/columns#basic-usage

因此,我有以下代码试图实现这个效果:

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>
};

然而,出现了某种原因,内容被截断了,就像这样,并且我无法弄清楚为什么。我已经检查了开发工具,尝试为整个容器设置自定义高度,为columns-3所定义的特定容器设置高度,但什么都没有起作用。

Tailwind栅格被切断 + 设置高度

我做错了什么?

英文:

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) =&gt; {
  const { data } = props;

  return (
    &lt;div className=&#39;rounded border p-4 mb-4&#39;&gt;
      {data}
    &lt;/div&gt;
  );
};

const Masonry = (props) =&gt; {
  const { data } = props;

  &lt;div className=&#39;columns-3&#39;&gt;
    {data.map((item) =&gt; (
      &lt;Tile
        key={item.name}
        data={item}
      /&gt;
    ))}
  &lt;/div&gt;
};

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.

Tailwind栅格被切断 + 设置高度

What am I doing wrong?

答案1

得分: 1

Apply break-inside: avoid-columnbreak-inside: avoidbreak-inside-avoid-columnbreak-inside-avoid 分别到 <Tile><div> 以避免您描述的行为:

英文:

Apply break-inside: avoid-column or break-inside: avoid with break-inside-avoid-column or break-inside-avoid respectively to the &lt;Tile&gt; root &lt;div&gt; to avoid the behavior you describe:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;

&lt;div class=&quot;columns-3&quot;&gt;
  &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
  &lt;/div&gt;
  &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
  &lt;/div&gt;
  &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
  &lt;/div&gt;
  &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
  &lt;/div&gt;
  &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
  &lt;/div&gt;
  &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
  &lt;/div&gt;
  &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
    Foo bar&lt;br/&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月22日 00:08:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525229.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定