1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

タグが画面からはみ出す問題のBefore / After【Tailwind CSS × Laravel】

Posted at

何をしたい?

テキストの折り返しで whitespace-nowrap を使用すると、単語途中で改行されなくて便利だが、その代わり1単語が長い時 & レスポンシブで画面が小さくなった時に、単語が画面から飛び出してしまう。↓
スクリーンショット 2025-04-29 14.01.31.png
スクリーンショット 2025-04-29 14.01.14.png

これをうまく綺麗に表示したい。

before

スクリーンショット 2025-04-29 14.01.31.png
スクリーンショット 2025-04-29 14.01.14.png

after

スクリーンショット 2025-04-29 14.02.34.png
スクリーンショット 2025-04-29 14.02.16.png

beforeコード

XXX.php
<h3 class="text-lg font-semibold mt-6 text-center">実装機能</h3>
<div class="flex flex-wrap justify-left gap-2 text-sm text-gray-600 mt-2">
    @foreach ($collection->featureTags as $featureTag)
        <span class="whitespace-nowrap">{{ $featureTag->name }}@if (!$loop->last)
                ,
            @endif
        </span>
    @endforeach
</div>

whitespace-nowrap によって改行されず、横幅が狭い画面で 画面外にはみ出る

afterコード

XXX.php
<h3 class="text-lg font-semibold mt-6 text-center">実装機能</h3>
<div class="flex flex-wrap break-words justify-left gap-2 text-sm text-gray-600 mt-2">
    @foreach ($collection->featureTags as $featureTag)
        <span>{{ $featureTag->name }}@if (!$loop->last),@endif</span>
    @endforeach
</div>

✅ 解決ポイント

✅ whitespace-nowrap を削除 → 改行が可能に
✅ 親divに break-words を追加 → 長い単語も自然に折り返す
✅ flex-wrap によって2行目に自然に折れる

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?