如何使用Tailwindcss防止CSS列换行

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

How to prevent css columns from wrapping with Tailwindcss

问题

使用Tailwind CSS,我有以下的HTML代码:

  1. <ol class="relative columns-1 sm:columns-3">
  2. <li>
  3. <img src="https://placehold.co/400x300">id=voluptas minus a qui tempore
  4. </li>
  5. <li>...</li>
  6. ...
  7. </ol>

ol 元素的相关Tailwind CSS代码是:

  1. .sm:columns-3 {
  2. columns: 3;
  3. }

正如您可以看到的(红色箭头),一个单元格被换行了。该单元格的其他部分位于中间列的底部。这是我不希望看到的,不想要换行。是否有方法可以防止这种情况发生,或者我应该确保所有单元格具有相同的高度?

英文:

Using tailwindcss I have the following html

  1. &lt;ol class=&quot;relative columns-1 sm:columns-3&quot;&gt;
  2. &lt;li&gt;
  3. &lt;img src=&quot;https://placehold.co/400x300&quot;&gt;id=voluptas minus a qui tempore
  4. &lt;/li&gt;
  5. &lt;li&gt;...&lt;/li&gt;
  6. ...
  7. &lt;/ol&gt;

The relevant Tailwind css for the ol is

  1. .sm:columns-3 {
  2. columns: 3;
  3. }

如何使用Tailwindcss防止CSS列换行

As you can see (red arrow) one cell is wrapped. The other part of that cell is at the bottom of the middle column. This is something I don't want, no wrapping. Is there some way this can be prevented or should I make sure that all cells have the same height?

答案1

得分: 1

为了防止Tailwind CSS中的CSS列换行,您可以使用break-inside属性。将break-inside设置为avoid-column以适用于<li>元素将防止它们跨列分割,您可以尝试以下逻辑:

  1. <ol class="relative columns-1 sm:columns-3">
  2. <li class="break-inside-avoid-column">
  3. <img src="https://placehold.co/400x300">id=voluptas minus a qui tempore
  4. </li>
  5. <li class="break-inside-avoid-column">...</li>
  6. ...
  7. </ol>

break-inside-avoid-column实用类由Tailwind CSS提供,并将break-inside属性设置为avoid-column。这确保每个<li>元素保持在其列内而不被分割。

英文:

To prevent CSS columns from wrapping in Tailwind CSS, you can use the break-inside property. Setting break-inside to avoid-column on the &lt;li&gt; elements will prevent them from being split across columns, you can try this logic:

  1. &lt;ol class=&quot;relative columns-1 sm:columns-3&quot;&gt;
  2. &lt;li class=&quot;break-inside-avoid-column&quot;&gt;
  3. &lt;img src=&quot;https://placehold.co/400x300&quot;&gt;id=voluptas minus a qui tempore
  4. &lt;/li&gt;
  5. &lt;li class=&quot;break-inside-avoid-column&quot;&gt;...&lt;/li&gt;
  6. ...
  7. &lt;/ol&gt;

The break-inside-avoid-column utility class is provided by Tailwind CSS and sets the break-inside property to avoid-column. This ensures that each &lt;li&gt; element remains intact within its column without being split.

huangapple
  • 本文由 发表于 2023年6月26日 21:53:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76557340.html
匿名

发表评论

匿名网友

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

确定