twitter-bootstrap-3 - 为什么可折叠 Bootstrap 面板中的表格会改变宽度?

标签 twitter-bootstrap-3 panel html-table collapsable

我在这里整理了一个 Bootply 演示:http://www.bootply.com/Ss2aAnzqlZ .

这是一个带有 table 的面板,符合 http://getbootstrap.com/components/#panels-tables .但是,我还使面板可折叠。折叠位工作正常,但 table 本身不保持形状。正如您将在 Bootply 中看到的,当您第一次加载页面时,它不会填充面板的宽度。当您单击面板标题中的“改进”以折叠面板时,表格在动画期间占据整个面板宽度,然后消失。当您再次单击以显示面板内容时,表格是全宽,直到动画停止,此时,它会收缩回看起来像“自动”宽度的宽度。

奇怪的是,检查 table 元素显示 table 本身是全宽的,但 thead、tbody 和 tfoot 不是。

我已经将其追溯到表格中“折叠”类的存在。如果您在没有“折叠”类的情况下启动 Bootply,则在折叠面板之前它是全宽的。当你展开它时,它会回到自动宽度。我不知道为什么......你呢?

这是代码片段,但折叠似乎没有在这里运行。 Bootply 更好。

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div style="margin:15px">
    <div class="panel panel-default">
        <div class="panel-heading">
            <a href="#" data-toggle="collapse" data-target="#improvementsPanel" aria-expanded="true" class="">Improvements</a>
        </div>
        <table id="improvementsPanel" class="table panel-collapse collapse in" aria-expanded="true" style="">
            <thead>
                <tr>
                    <th>Description</th>
                    <th class="text-right">Qty</th>
                    <th>UOM</th>
                    <th class="text-right">Rate</th>
                    <th class="text-right">Value</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Item 1</td>
                    <td class="text-right">133.00</td>
                    <td>m²</td>
                    <td class="text-right">425.00</td>
                    <td class="text-right">56,525</td>
                </tr>
                <tr>
                    <td>Item 2</td>
                    <td class="text-right">85.00</td>
                    <td>m²</td>
                    <td class="text-right">70.00</td>
                    <td class="text-right">5,950</td>
                </tr>
                <tr>
                    <td>Item 3</td>
                    <td class="text-right">25.00</td>
                    <td>m²</td>
                    <td class="text-right">100.00</td>
                    <td class="text-right">2,500</td>
                </tr>
                <tr>
                    <td>Item 4</td>
                    <td class="text-right"></td>
                    <td></td>
                    <td class="text-right"></td>
                    <td class="text-right">1,500</td>
                </tr>
            </tbody>
            <tfoot>
                <tr>
                    <th class="text-right" colspan="4">Total</th>
                    <th class="text-right">66,475</th>
                </tr>
            </tfoot>
        </table>
    </div>
</div>

最佳答案

collapse class 在 none 之间切换表格上的显示样式和 block这似乎干扰了标准表格 CSS。

您可以通过将表格放入 div 并将该 div 设置为折叠而不是表格来解决此问题。

新 Bootply:http://www.bootply.com/L8h2OdpMuD

HTML:

<div style="margin: 15px">
    <div class="panel panel-default">
        <div class="panel-heading">
            <a href="#" data-toggle="collapse" data-target="#improvementsPanel" aria-expanded="true" class="">Improvements</a>
        </div>
        <div id="improvementsPanel" class="panel-collapse collapse in" aria-expanded="true">
            <table class="table">
                <thead>
                    <tr>
                        <th>Description</th>
                        <th class="text-right">Qty</th>
                        <th>UOM</th>
                        <th class="text-right">Rate</th>
                        <th class="text-right">Value</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>Item 1</td>
                        <td class="text-right">133.00</td>
                        <td>m²</td>
                        <td class="text-right">425.00</td>
                        <td class="text-right">56,525</td>
                    </tr>
                    <tr>
                        <td>Item 2</td>
                        <td class="text-right">85.00</td>
                        <td>m²</td>
                        <td class="text-right">70.00</td>
                        <td class="text-right">5,950</td>
                    </tr>
                    <tr>
                        <td>Item 3</td>
                        <td class="text-right">25.00</td>
                        <td>m²</td>
                        <td class="text-right">100.00</td>
                        <td class="text-right">2,500</td>
                    </tr>
                    <tr>
                        <td>Item 4</td>
                        <td class="text-right"></td>
                        <td></td>
                        <td class="text-right"></td>
                        <td class="text-right">1,500</td>
                    </tr>
                </tbody>
                <tfoot>
                    <tr>
                        <th class="text-right" colspan="4">Total</th>
                        <th class="text-right">66,475</th>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>

关于twitter-bootstrap-3 - 为什么可折叠 Bootstrap 面板中的表格会改变宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26923543/

相关文章:

html - 将上下文类应用于导航栏中的列表项

html - Bootstrap 3 页脚出现严重问题, Logo 对齐导致出现水平滚动条

javascript - 滑动面板 onClick

forms - 在管理面板表单 magento 中添加一些 HTML

php - 尝试按公共(public)值对 TR 行进行分组

javascript - 我们是否有任何 CSS 框架来制作桌面优先的 Web 应用程序

javascript - 调整大小时如何修复页脚重叠内容

css - 如何做一个 'gray box' 或内联面板?

html - 将 span 换行到表格单元格内

Python 请求 html,我没有在网页中获取完整数组 - url=cmegroup