Tailwind栅格被切断 + 设置高度

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

Tailwind Columns Cutting Off + Setting Height

问题

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

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

  1. const Tile = (props) => {
  2. const { data } = props;
  3. return (
  4. <div className='rounded border p-4 mb-4'>
  5. {data}
  6. </div>
  7. );
  8. };
  9. const Masonry = (props) => {
  10. const { data } = props;
  11. <div className='columns-3'>
  12. {data.map((item) => (
  13. <Tile
  14. key={item.name}
  15. data={item}
  16. />
  17. ))}
  18. </div>
  19. };

然而,出现了某种原因,内容被截断了,就像这样,并且我无法弄清楚为什么。我已经检查了开发工具,尝试为整个容器设置自定义高度,为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:

  1. const Tile = (props) =&gt; {
  2. const { data } = props;
  3. return (
  4. &lt;div className=&#39;rounded border p-4 mb-4&#39;&gt;
  5. {data}
  6. &lt;/div&gt;
  7. );
  8. };
  9. const Masonry = (props) =&gt; {
  10. const { data } = props;
  11. &lt;div className=&#39;columns-3&#39;&gt;
  12. {data.map((item) =&gt; (
  13. &lt;Tile
  14. key={item.name}
  15. data={item}
  16. /&gt;
  17. ))}
  18. &lt;/div&gt;
  19. };

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

  1. &lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;
  2. &lt;div class=&quot;columns-3&quot;&gt;
  3. &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
  4. Foo bar&lt;br/&gt;
  5. Foo bar&lt;br/&gt;
  6. Foo bar&lt;br/&gt;
  7. Foo bar&lt;br/&gt;
  8. Foo bar&lt;br/&gt;
  9. &lt;/div&gt;
  10. &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
  11. Foo bar&lt;br/&gt;
  12. Foo bar&lt;br/&gt;
  13. Foo bar&lt;br/&gt;
  14. Foo bar&lt;br/&gt;
  15. Foo bar&lt;br/&gt;
  16. &lt;/div&gt;
  17. &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
  18. Foo bar&lt;br/&gt;
  19. Foo bar&lt;br/&gt;
  20. Foo bar&lt;br/&gt;
  21. Foo bar&lt;br/&gt;
  22. Foo bar&lt;br/&gt;
  23. &lt;/div&gt;
  24. &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
  25. Foo bar&lt;br/&gt;
  26. Foo bar&lt;br/&gt;
  27. Foo bar&lt;br/&gt;
  28. Foo bar&lt;br/&gt;
  29. Foo bar&lt;br/&gt;
  30. &lt;/div&gt;
  31. &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
  32. Foo bar&lt;br/&gt;
  33. Foo bar&lt;br/&gt;
  34. Foo bar&lt;br/&gt;
  35. Foo bar&lt;br/&gt;
  36. Foo bar&lt;br/&gt;
  37. &lt;/div&gt;
  38. &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
  39. Foo bar&lt;br/&gt;
  40. Foo bar&lt;br/&gt;
  41. Foo bar&lt;br/&gt;
  42. Foo bar&lt;br/&gt;
  43. Foo bar&lt;br/&gt;
  44. &lt;/div&gt;
  45. &lt;div class=&quot;rounded border p-4 mb-4 break-inside-avoid-column&quot;&gt;
  46. Foo bar&lt;br/&gt;
  47. Foo bar&lt;br/&gt;
  48. Foo bar&lt;br/&gt;
  49. Foo bar&lt;br/&gt;
  50. Foo bar&lt;br/&gt;
  51. &lt;/div&gt;
  52. &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:

确定