Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make a table scrollable with html + Tailwind CSS

i have this table like in the image below, it is overflow from the right side, how can I add scrolling, I am using Tailwind CSS like in this code:

  <table class="table-auto overflow-scroll">
                    <thead>
                    <tr class="bg-gray-100">
                        <th class="w-20 px-4 py-2">No.</th>
                        <th class="px-4 py-2">First Name</th>
                        <th class="px-4 py-2">Second Name</th>
                        <th class="px-4 py-2">Third Name</th>
                        <th class="px-4 py-2">Department</th>
                        <th class="px-4 py-2">Stage</th>
                        <th class="px-4 py-2">Email</th>
                        <th class="px-4 py-2">Roles</th>
                        <th class="px-4 py-2">status</th>
                        <th class="px-4 py-2">University Email</th>
                        <th class="px-4 py-2">University Password</th>
                        <th class="px-4 py-2">Students Files</th>
                        <th class="px-4 py-2">Actions</th>
                    </tr>
                    </thead>
                    <tbody>

                        @if(isset($users)) @include('dashboard.users.partials.users_details') @endif
                        @if(isset($searches)) @include('dashboard.users.partials.search') @endif
                        @if(isset($statusSearch)) @include('dashboard.users.partials.status_search') @endif

                    </tbody>
                </table>

enter image description here

like image 270
Osama Mohammed Avatar asked Jun 11 '26 21:06

Osama Mohammed


2 Answers

Wrap your table with a div with overflow-x class and your required width, and add w-full class to your table class.

<div class='overflow-x'>
        <table class='table-auto overflow-scroll w-full'>
            <thead>
                <tr class='bg-gray-100'>
                    <th class='w-20 px-4 py-2'>No.</th>
                    <th class='px-4 py-2'>First Name</th>
                    <th class='px-4 py-2'>Second Name</th>
                    <th class='px-4 py-2'>Third Name</th>
                    <th class='px-4 py-2'>Department</th>
                    <th class='px-4 py-2'>Stage</th>
                    <th class='px-4 py-2'>Email</th>
                    <th class='px-4 py-2'>Roles</th>
                    <th class='px-4 py-2'>status</th>
                    <th class='px-4 py-2'>University Email</th>
                    <th class='px-4 py-2'>University Password</th>
                    <th class='px-4 py-2'>Students Files</th>
                    <th class='px-4 py-2'>Actions</th>
                </tr>
            </thead>
            <tbody>
                @if(isset($users))
                @include('dashboard.users.partials.users_details') @endif
                @if(isset($searches))
                @include('dashboard.users.partials.search') @endif
                @if(isset($statusSearch))
                @include('dashboard.users.partials.status_search') @endif
            </tbody>
        </table>
    </div>
like image 109
Ali Zeinalzadeh Avatar answered Jun 14 '26 12:06

Ali Zeinalzadeh


<div class="overflow-auto ..."></div> you can try this 

tailewindcss link

like image 31
shawonwebdev Avatar answered Jun 14 '26 11:06

shawonwebdev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!