html - 使模态内的 Bootstrap 表可滚动

标签 html css twitter-bootstrap

如何使 Bootstrap 表在带有固定标题的模态滚动中呈现?目前我的模态主体是可滚动的,这使得表头在滚动时消失。

enter image description here

代码

<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
            <input type="text" id="market-search" onkeyup="marketSearch()" placeholder="Search for stock names..">
        <i class="fa fa-times" data-dismiss="modal"></i>
        </div>
        <div class="modal-body">
             <div class="card">
                 <div id="table" class="table-editable">
                     <table id="modal-table" class="sortable table table-bordered table-responsive-md table-hover">
                         <thead class="thead-dark">
                         <tr >
                             <th>Code</th>
                             <th>Name</th>
                             <th>LTP</th>
                             <th>Open Price</th>
                             <th>Previous Close</th>
                             <th>Low52</th>
                             <th>High52</th>
                             <th>Percentage (%)</th>
                             <th>Allocate</th>
                         </tr>
                         </thead>
                         <tbody id="allocate-table-body">
                         {% for stock in all_stocks %}
                         <tr id="stock_{{stock.code}}" class="stock-card" data-name="{{stock.name}}">
                             <td><a target="_blank" style="color:blue;" href="https://www.google.com/finance?q=NSE:{{ stock.code }}">{{stock.code}}</a></td>
                             <td>{{stock.name}}</td>
                             <td>{{stock.price}}</td>
                             <td>{{stock.open_price}}</td>
                             <td>{{stock.previous_close}}</td>
                             <td>{{stock.low52}}</td>
                             <td>{{stock.high52}}</td>
                             <td>
                                 <input type="number" id="input_{{stock.code}}" class="stockme"/>
                             </td>
                             <td>
                                 <a style="white-space:nowrap" href="#" class="btn btn-primary btn-success market-buy-button" onclick=insertRow("{{current_allocation}}","{{stock.code}}","{{stock.name|to_and}}","{{stock.price}}","{{stock.diff}}")>Allocate</a>
                             </td>
                         </tr>
                         {% endfor %}
                         </tbody>
                     </table>
                 </div>
             </div>
        </div>
    </div>
</div>

CSS

.modal-dialog,
.modal-content {
    /* 100% of window height */
    height: 95%;
}

.modal-body {
    /* 100% = dialog height, 120px = header + footer */
    overflow-y: scroll;
}

我还想降低行高。

这里的任何线索都非常可观。

最佳答案

你可以试试这个。

#allocate-table-body {
max-height : 300px;
overflow-y: auto;
}

关于html - 使模态内的 Bootstrap 表可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57929358/

相关文章:

html - 是否必须在 http header 中设置 cookie?

php - Float 导致空的 div 消失 - 为什么?

css - 字体不变

javascript - 模态对话框验证 ASP.NET/bootstrap

c# - 将 fontawesome 图标添加到 asp.net 按钮

html - 浏览器无法正确解析HTML-Grails 2

javascript - 关闭浏览器时向数据库发送查询

javascript - 如何在输入文本密码上贴上标签以避免这些子弹?

html - 在移动浏览器中使用自动填充功能将背景图像添加到输入字段 - 默认黄色背景会删除它们

html - 如何使用 Bootstrap 获得单个下拉列表