I have a problem with horozontal scroll in tailwind css (not scroll):
<div class="flex items-center mb-10 overflow-x-auto flex-none carousel pr-10
opacity-at-end mt-16 flex-row-reverse">
<?php $tags = $data->tags; ?> @foreach ($tags as $tag)
<a class=" flex-none">
</a>
<a class="active bg-white tertiary-color fs-18 fw-400 radius rounded-[30px]
pt-4 pb-3 px-5 min-h-[44px] text-center ml-5 flex-none">
{{ $tag->name }}
</a> @endforeach
</div>
Your parent element must either have a set width
or max-width
in order for overflow to work . You can use tailwind's max width utility class to add a max-width
to the parent element as follows:
<div class="max-w-md">
<div class="flex items-center mb-10 overflow-x-auto flex-none carousel pr-10 opacity-at-end mt-16 flex-row-reverse">
<?php $tags = $data->tags; ?>
@foreach ($tags as $tag)
<a class=" flex-none"></a>
<a class="active bg-white tertiary-color fs-18 fw-400 radius rounded-[30px] pt-4 pb-3 px-5 min-h-[44px] text-center ml-5 flex-none">
{{ $tag->name }}
</a>
@endforeach
</div>
</div>
You can replace overflow-x-scroll
instead of overflow-x-auto
and make the width somewhat smaller so that you can see the scroll behavior with 2-3 items only.
Below is the code you can check,
<script src="https://cdn.tailwindcss.com"></script> <div class="carousel opacity-at-end mx-auto mb-10 mt-16 flex w-1/2 flex-none flex-row-reverse items-center overflow-x-scroll bg-slate-300 p-4 pr-10"> <a class="flex-none"> </a> <a class="active tertiary-color fs-18 fw-400 radius ml-5 min-h-[44px] flex-none rounded-[30px] bg-slate-400 px-5 pt-4 pb-3 text-center"> $tag->name </a> <a class="flex-none"> </a> <a class="active tertiary-color fs-18 fw-400 radius ml-5 min-h-[44px] flex-none rounded-[30px] bg-slate-400 px-5 pt-4 pb-3 text-center"> $tag->name </a> <a class="flex-none"> </a> <a class="active tertiary-color fs-18 fw-400 radius ml-5 min-h-[44px] flex-none rounded-[30px] bg-slate-400 px-5 pt-4 pb-3 text-center"> $tag->name </a> <a class="flex-none"> </a> <a class="active tertiary-color fs-18 fw-400 radius ml-5 min-h-[44px] flex-none rounded-[30px] bg-slate-400 px-5 pt-4 pb-3 text-center"> $tag->name </a> <a class="flex-none"> </a> <a class="active tertiary-color fs-18 fw-400 radius ml-5 min-h-[44px] flex-none rounded-[30px] bg-slate-400 px-5 pt-4 pb-3 text-center"> $tag->name </a> a </div>
I had added 5-6 tags manually instead of for loop. Check in full view
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.