【问题标题】:Boostrap table not responsive引导表无响应
【发布时间】:2020-06-17 10:39:43
【问题描述】:

我正在使用引导程序做一个简单的网站。现在, 里面有一些信息。

我确实在互联网上查看了如何使其具有响应性,但到目前为止还没有。有人有可以帮助我的链接吗?

这是代码(很长,抱歉)

<div class="container">
        <div class="row justify-content-center" style="color:#002D59">
            <div class="col-xl-7 col-lg-8 col-md-10 col-sm-12 mx-auto text-center p-4">
                <div class="mt-3 mb-3 text-center">
                    <nav class="nav nav-tabs">
                        <a class="nav-item nav-link active " href="#test1" data-toggle="tab">Test 1 tab here</a>
                        <a class="nav-item nav-link" href="#test2" data-toggle="tab">Test 2</a>
                        <a class="nav-item nav-link" href="#test3" data-toggle="tab">Test 3 here hey</a>
                        <a class="nav-item nav-link" href="#test4" data-toggle="tab">im here test 4</a>
                    </nav>
                    <div class="tab-content">
                        <div class="tab-pane fade show active" id="test1">

                            <table class="table table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th scope="col">ID</th>
                                        <th scope="col">Date of creation</th>
                                        <th scope="col">detail</th>
                                        <th scope="col">state</th>
                                        <th scope="col">comments</th>
                                    </tr>
                                </thead>
                                <tbody>
                                        <tr>
                                            <th scope="row">1</th>
                                            <td>21/02/2020</td>
                                            <td>
                                                <div class="col-sm text-center">
                                                    <a class="btn btn-sm" href="#" role="button" style="background-color: #002D59; color: #FFFFFF; border-radius: 10px">
                                                        Link
                                                    </a>
                                                </div>

                                            </td>
                                            <td>description here</td>
                                            <td>comments over here</td>
                                        </tr>
                                </tbody>
                            </table>
                        </div>

其他 3 个代码相同。

真诚的

【问题讨论】:

    标签: html bootstrap-4 responsive-design


    【解决方案1】:

    使用table-responsive 类使表格具有响应性。

    您还可以使用一些 CSS 属性来使表格更具响应性。

    tr td {
        word-break: break-all;
        overflow-wrap: break-word;
        max-width: 30rem;
    }
    

    这里将所有td 提供给max-width: 30rem ( 1rem = 16px ) 并允许在表格内容中分词。

    tr td:nth-child(2) {
        min-width: 15rem !important;
    }
    
    

    在设置max-width 后,所有td 会自动设置其宽度,但有时像email fielddescription field 一样,您需要更大的宽度,因此,您可以将min-width: 15rem 或 设置为特定的td

    希望以上步骤对您有所帮助。

    更新

    要使nav-tabs 响应,您可以使用flexbox

    这里我使用了flex-column flex-sm-row 两个类来让你的nav-tabs 响应。

    你可以在https://getbootstrap.com/docs/4.4/utilities/flex/查看这些课程

    工作示例

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    
    <div class="container">
        <div class="row justify-content-center" style="color:#002D59">
            <div class="col-xl-7 col-lg-8 col-md-10 col-sm-12 mx-auto text-center p-4">
                <div class="mt-3 mb-3 text-center">
                    <nav class="nav nav-tabs flex-column flex-sm-row">
                        <a class="nav-item nav-link active " href="#test1" data-toggle="tab">Test 1 tab here</a>
                        <a class="nav-item nav-link" href="#test2" data-toggle="tab">Test 2</a>
                        <a class="nav-item nav-link" href="#test3" data-toggle="tab">Test 3 here hey</a>
                        <a class="nav-item nav-link" href="#test4" data-toggle="tab">im here test 4</a>
                    </nav>
                    <div class="tab-content">
                        <div class="tab-pane fade show active" id="test1">
                            <div class="table-responsive">
                                <table class="table table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th scope="col">ID</th>
                                            <th scope="col">Date of creation</th>
                                            <th scope="col">detail</th>
                                            <th scope="col">state</th>
                                            <th scope="col">comments</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <th scope="row">1</th>
                                            <td>21/02/2020</td>
                                            <td>
                                                <div class="col-sm text-center">
                                                    <a class="btn btn-sm" href="#" role="button" style="background-color: #002D59; color: #FFFFFF; border-radius: 10px">Link</a>
                                                </div>
                                            </td>
                                            <td>description here</td>
                                            <td>comments over here</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

    【讨论】:

    • 谢谢!还有一件事,我的onglet看起来很糟糕,有办法让它看起来不错吗? (查看图片的原始帖子,因为我无法在评论中发布图片)是否可以将其作为下拉菜单或其他内容?
    猜你喜欢
    • 2018-10-14
    • 1970-01-01
    • 2022-08-17
    • 2019-06-28
    • 1970-01-01
    • 2023-03-29
    • 2016-10-31
    • 2015-10-19
    • 1970-01-01
    相关资源
    最近更新 更多