【问题标题】:Bootstrap table extending beyond the panel when resizing the browser调整浏览器大小时,引导表超出面板
【发布时间】:2016-09-29 20:41:51
【问题描述】:

我正在尝试构建一个内部带有表格的面板。代码如下所示:

<div class="container">
              <div class="row">
               <div class="panel panel-default col-xs-12">

             <div class="panel">
               <div class="panel-heading bg-primary">
                <h3 class="panel-title">This is a panel</h3>
              </div>

              <div class="panel-body">
                <p>What is Lorem Ipsum?
                 Lorem Ipsum is simply dummy text of the printing and  typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p.
              </div> <!-- panel body -->

                <!-- Table inside the panel -->
                <table class="table">
                  <thead>
                    <tr>
                      <th>Firstname</th>
                      <th>Lastname</th>
                      <th>Email</th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td>John</td>
                      <td>Doe</td>
                      <td>john@example.com</td>
                    </tr>
                    <tr>
                      <td>Mary</td>
                      <td>Moe</td>
                      <td>mary@example.com</td>
                    </tr>
                    <tr>
                      <td>July</td>
                      <td>Dooley</td>
                      <td>july@example.com</td>
                    </tr>
                  </tbody>
                </table>
              </div> <!-- panel -->


          </div> <!-- row -->
        </div> <!-- container --> 

面板在大多数屏幕尺寸上看起来都不错,除了桌面打破面板的移动设备。我不确定我做错了什么,因为该示例与 Bootstrap 网站上的示例非常相似,并且它似乎对所有屏幕尺寸都有响应。谢谢!

【问题讨论】:

    标签: html css twitter-bootstrap multiple-columns


    【解决方案1】:

    尝试将 .table 包装在 table-responsive

    panel 包装在col-xs-12 中并从面板本身中删除 col 类(面板将始终跨越其父级的全宽)

    在您的panel-body 中包含table

    我还注意到&lt;p&gt; 标记未在您的panel-body 中关闭:p

    希望这会有所帮助!

    <div class="container">
      <div class="row">
        <div class="col-xs-12">
          <div class="panel panel-default">
    
            <div class="panel">
              <div class="panel-heading bg-primary">
                <h3 class="panel-title">This is a panel</h3>
              </div>
    
              <div class="panel-body">
                <p>What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to
                  make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum
                  passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    
                <!-- Table inside the panel -->
                <div class="table-responsive">
                  <table class="table">
                    <thead>
                      <tr>
                        <th>Firstname</th>
                        <th>Lastname</th>
                        <th>Email</th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr>
                        <td>John</td>
                        <td>Doe</td>
                        <td>john@example.com</td>
                      </tr>
                      <tr>
                        <td>Mary</td>
                        <td>Moe</td>
                        <td>mary@example.com</td>
                      </tr>
                      <tr>
                        <td>July</td>
                        <td>Dooley</td>
                        <td>july@example.com</td>
                      </tr>
                    </tbody>
                  </table>
                </div>
              </div>
            </div>

    【讨论】:

    • 表格不再脱离面板,但底部仍然有水平滚动条。我知道这是窗口浏览器太小的正常行为,所以我想知道是否有任何解决方案可以使整个表格即使在小屏幕尺寸上也能显示,而无需向左/向右滚动。谢谢!
    • 不是真的 Casia :( 事情就是这样。
    【解决方案2】:

    您是否尝试过 .table-responsive 父 div 类?

    <div class="table-responsive">
      <table class="table">
       ...
      </table>
    </div>
    

    【讨论】:

    • 我试过
    • 尝试仅使用表格响应的 div。
      正如您在我的回答中看到的那样。
    • 不,它不起作用。该解决方案使表格更大,并在页面底部为我提供了一个滚动条。
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签