html - 如何使用 html + Tailwind CSS 使表格可滚动

我有如下图所示的表格,它从右侧溢出,我如何添加滚动,我在这段代码中使用 Tailwind CSS:

  <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>

最佳答案

用带有 overflow-x 类和所需宽度的 div 包裹您的表格,并将 w-full 类添加到您的表格类中。

<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>

https://stackoverflow.com/questions/71485050/

相关文章:

amazon-web-services - 如何将事件从 EventBridge 发送到 Lambd

c++ - 没有非空函数的返回语句是否是未定义的行为,其中控制永远不会结束?

typescript - 我可以根据参数更改返回类型吗

javascript - 我将如何在 P5.js 的 Canvas 上的两个位置之间创建点?

python - 给定一个数字,找到到达它的序列

laravel - 如何通过单击进入 vs 代码中的一个类

reactjs - webpack-cli : Invalid options object. De

vue.js - Vitest 与 Quasar 的集成

r - 取消列出嵌套列表的倒数第二个列表

c++ - 为什么 deques 默认用作堆栈的底层容器,而 vectors 可以做到这一点?