Tailwind Flex:显示一长行文本时溢出
Tailwind Flex: Overflow when a long line of text is shown
这是我从 Flex classes in tailwind 得到的一个非常奇怪的行为。我想您可以以某种方式将其转换为 CSS,但我想留在顺风解决方案中。让我解释一下:
如果您 运行 下面的代码片段,您将看到在第一种情况下,该行溢出,即使我尝试使用 break-words
class。 break-all
class 不会发生这种情况,但我不想使用 class,因为它可能会打断文字。
当您输出一些普通文本时,它的行为符合您的预期。
这是个问题吗?我是完美主义者吗?
谢谢!
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<!-- My problem. It should break the line and avoid the overflow-->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
asuperultraloooooooooonglineoftexoverhereitfeelslikeitdoesnotendddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
</div>
</div>
<!-- When words are smaller it behaves just fine! -->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem
</div>
</div>
解决此问题的几种方法
添加也溢出:隐藏
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<!-- My problem. It should break the line and avoid the overflow-->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words overflow-hidden">
asuperultraloooooooooonglineoftexoverhereitfeelslikeitdoesnotendddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
</div>
</div>
<!-- When words are smaller it behaves just fine! -->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem
</div>
</div>
设置静态宽度
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<!-- My problem. It should break the line and avoid the overflow-->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="w-64 flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
asuperultraloooooooooonglineoftexoverhereitfeelslikeitdoesnotendddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
</div>
</div>
<!-- When words are smaller it behaves just fine! -->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem
</div>
</div>
我也在尝试寻找其他方法,但老实说,我不是 100% 确定为什么会这样——我不是 flexbox 专家。
这是我从 Flex classes in tailwind 得到的一个非常奇怪的行为。我想您可以以某种方式将其转换为 CSS,但我想留在顺风解决方案中。让我解释一下:
如果您 运行 下面的代码片段,您将看到在第一种情况下,该行溢出,即使我尝试使用 break-words
class。 break-all
class 不会发生这种情况,但我不想使用 class,因为它可能会打断文字。
当您输出一些普通文本时,它的行为符合您的预期。
这是个问题吗?我是完美主义者吗?
谢谢!
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<!-- My problem. It should break the line and avoid the overflow-->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
asuperultraloooooooooonglineoftexoverhereitfeelslikeitdoesnotendddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
</div>
</div>
<!-- When words are smaller it behaves just fine! -->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem
</div>
</div>
解决此问题的几种方法
添加也溢出:隐藏
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<!-- My problem. It should break the line and avoid the overflow-->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words overflow-hidden">
asuperultraloooooooooonglineoftexoverhereitfeelslikeitdoesnotendddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
</div>
</div>
<!-- When words are smaller it behaves just fine! -->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem
</div>
</div>
设置静态宽度
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<!-- My problem. It should break the line and avoid the overflow-->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="w-64 flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
asuperultraloooooooooonglineoftexoverhereitfeelslikeitdoesnotendddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
</div>
</div>
<!-- When words are smaller it behaves just fine! -->
<div class="flex bg-gray-200">
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2">
Short
</div>
<div class="flex-initial text-gray-700 text-center bg-gray-400 px-4 py-2 m-2 break-words">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui ad labore ipsam, aut rem quo repellat esse tempore id, quidem
</div>
</div>
我也在尝试寻找其他方法,但老实说,我不是 100% 确定为什么会这样——我不是 flexbox 专家。