css - 带 Bootstrap 的替代网格

标签 css twitter-bootstrap responsive-design media-queries

我想要一个响应式网格系统,它可以将我的标题连接到具有最小媒体查询的所有行。我知道有一些像本页 http://exisweb.net/responsive-table-plugins-and-patterns 上的解决方案一样的解决方案。 .

有人知道允许使用 Bootstrap 实现此类功能的插件或方法吗?我已经查过了 http://startbootstrap.com/bootstrap-resources/但没有发现那样的东西。另一种可接受的方法是在某个时间点修复表格标题,以便浏览表格的用户始终可以看到它们,即使他向下滚动整个页面也是如此。

最佳答案

试试这个!我不知道这是否正是您的意思:

@media only screen and (max-width: 800px) {
            /* Force table to not be like tables anymore */
            
            #no-more-tables table,
            #no-more-tables thead,
            #no-more-tables tbody,
            #no-more-tables th,
            #no-more-tables td,
            #no-more-tables tr {
                display: block;
            }
            /* Hide table headers (but not display: none;, for accessibility) */
            
            #no-more-tables thead tr {
                position: absolute;
                top: -9999px;
                left: -9999px;
            }
            #no-more-tables tr {
                border: 1px solid #ccc;
            }
            #no-more-tables td {
                /* Behave  like a "row" */
                
                border: none;
                border-bottom: 1px solid #eee;
                position: relative;
                padding-left: 50%;
                white-space: normal;
                text-align: left;
            }
            #no-more-tables td:before {
                /* Now like a table header */
                
                position: absolute;
                /* Top/left values mimic padding */
                
                top: 6px;
                left: 6px;
                width: 45%;
                padding-right: 10px;
                white-space: nowrap;
                text-align: left;
                font-weight: bold;
            }
            /*
	Label the data
	*/
            
            #no-more-tables td:before {
                content: attr(data-title);
            }
        }
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Getting Started With Bootstrap</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
</head>

<body>
    <div class="container">
        <div class="row">
            <div id="no-more-tables">
                <table class="col-md-12 table-bordered table-striped table-condensed">
                    <thead>
                        <tr>
                            <th>Code</th>
                            <th>Company</th>
                            <th class="number">Price</th>
                            <th class="number">Change</th>
                            <th class="number">Change %</th>
                            <th class="number">Open</th>
                            <th class="number">High</th>
                            <th class="number">Low</th>
                            <th class="number">Volume</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td data-title="Code">AAC</td>
                            <td data-title="Company">AUSTRALIAN AGRICULTURAL COMPANY LIMITED.</td>
                            <td data-title="Price" class="number">$1.38</td>
                            <td data-title="Change" class="number">-0.01</td>
                            <td data-title="Change %" class="number">-0.36%</td>
                            <td data-title="Open" class="number">$1.39</td>
                            <td data-title="High" class="number">$1.39</td>
                            <td data-title="Low" class="number">$1.38</td>
                            <td data-title="Volume" class="number">9,395</td>
                        </tr>
                        <tr>
                            <td data-title="Code">AAD</td>
                            <td data-title="Company">ARDENT LEISURE GROUP</td>
                            <td data-title="Price" class="number">$1.15</td>
                            <td data-title="Change" class="number">+0.02</td>
                            <td data-title="Change %" class="number">1.32%</td>
                            <td data-title="Open" class="number">$1.14</td>
                            <td data-title="High" class="number">$1.15</td>
                            <td data-title="Low" class="number">$1.13</td>
                            <td data-title="Volume" class="number">56,431</td>
                        </tr>
                        <tr>
                            <td data-title="Code">AAX</td>
                            <td data-title="Company">AUSENCO LIMITED</td>
                            <td data-title="Price" class="number">$4.00</td>
                            <td data-title="Change" class="number">-0.04</td>
                            <td data-title="Change %" class="number">-0.99%</td>
                            <td data-title="Open" class="number">$4.01</td>
                            <td data-title="High" class="number">$4.05</td>
                            <td data-title="Low" class="number">$4.00</td>
                            <td data-title="Volume" class="number">90,641</td>
                        </tr>
                        <tr>
                            <td data-title="Code">ABC</td>
                            <td data-title="Company">ADELAIDE BRIGHTON LIMITED</td>
                            <td data-title="Price" class="number">$3.00</td>
                            <td data-title="Change" class="number">+0.06</td>
                            <td data-title="Change %" class="number">2.04%</td>
                            <td data-title="Open" class="number">$2.98</td>
                            <td data-title="High" class="number">$3.00</td>
                            <td data-title="Low" class="number">$2.96</td>
                            <td data-title="Volume" class="number">862,518</td>
                        </tr>
                        <tr>
                            <td data-title="Code">ABP</td>
                            <td data-title="Company">ABACUS PROPERTY GROUP</td>
                            <td data-title="Price" class="number">$1.91</td>
                            <td data-title="Change" class="number">0.00</td>
                            <td data-title="Change %" class="number">0.00%</td>
                            <td data-title="Open" class="number">$1.92</td>
                            <td data-title="High" class="number">$1.93</td>
                            <td data-title="Low" class="number">$1.90</td>
                            <td data-title="Volume" class="number">595,701</td>
                        </tr>
                        <tr>
                            <td data-title="Code">ABY</td>
                            <td data-title="Company">ADITYA BIRLA MINERALS LIMITED</td>
                            <td data-title="Price" class="number">$0.77</td>
                            <td data-title="Change" class="number">+0.02</td>
                            <td data-title="Change %" class="number">2.00%</td>
                            <td data-title="Open" class="number">$0.76</td>
                            <td data-title="High" class="number">$0.77</td>
                            <td data-title="Low" class="number">$0.76</td>
                            <td data-title="Volume" class="number">54,567</td>
                        </tr>
                        <tr>
                            <td data-title="Code">ACR</td>
                            <td data-title="Company">ACRUX LIMITED</td>
                            <td data-title="Price" class="number">$3.71</td>
                            <td data-title="Change" class="number">+0.01</td>
                            <td data-title="Change %" class="number">0.14%</td>
                            <td data-title="Open" class="number">$3.70</td>
                            <td data-title="High" class="number">$3.72</td>
                            <td data-title="Low" class="number">$3.68</td>
                            <td data-title="Volume" class="number">191,373</td>
                        </tr>
                        <tr>
                            <td data-title="Code">ADU</td>
                            <td data-title="Company">ADAMUS RESOURCES LIMITED</td>
                            <td data-title="Price" class="number">$0.72</td>
                            <td data-title="Change" class="number">0.00</td>
                            <td data-title="Change %" class="number">0.00%</td>
                            <td data-title="Open" class="number">$0.73</td>
                            <td data-title="High" class="number">$0.74</td>
                            <td data-title="Low" class="number">$0.72</td>
                            <td data-title="Volume" class="number">8,602,291</td>
                        </tr>
                        <tr>
                            <td data-title="Code">AGG</td>
                            <td data-title="Company">ANGLOGOLD ASHANTI LIMITED</td>
                            <td data-title="Price" class="number">$7.81</td>
                            <td data-title="Change" class="number">-0.22</td>
                            <td data-title="Change %" class="number">-2.74%</td>
                            <td data-title="Open" class="number">$7.82</td>
                            <td data-title="High" class="number">$7.82</td>
                            <td data-title="Low" class="number">$7.81</td>
                            <td data-title="Volume" class="number">148</td>
                        </tr>
                        <tr>
                            <td data-title="Code">AGK</td>
                            <td data-title="Company">AGL ENERGY LIMITED</td>
                            <td data-title="Price" class="number">$13.82</td>
                            <td data-title="Change" class="number">+0.02</td>
                            <td data-title="Change %" class="number">0.14%</td>
                            <td data-title="Open" class="number">$13.83</td>
                            <td data-title="High" class="number">$13.83</td>
                            <td data-title="Low" class="number">$13.67</td>
                            <td data-title="Volume" class="number">846,403</td>
                        </tr>
                        <tr>
                            <td data-title="Code">AGO</td>
                            <td data-title="Company">ATLAS IRON LIMITED</td>
                            <td data-title="Price" class="number">$3.17</td>
                            <td data-title="Change" class="number">-0.02</td>
                            <td data-title="Change %" class="number">-0.47%</td>
                            <td data-title="Open" class="number">$3.11</td>
                            <td data-title="High" class="number">$3.22</td>
                            <td data-title="Low" class="number">$3.10</td>
                            <td data-title="Volume" class="number">5,416,303</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
</body>

</html>

关于css - 带 Bootstrap 的替代网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29494058/

相关文章:

css - 使用 CSS 调整图像大小以适合显示

html - 为什么 Adob​​e XD 中的 100 像素小于网站(Safari、Google Chrome 等)中的 100 像素?

javascript - 调整浏览器窗口大小时,内部 Div 字体大小不会随媒体查询而改变

jquery - 选择子菜单时 Bootstrap 下拉列表添加复选图标

javascript - 在 HTML 5 Canvas 的每一侧对齐文本

css - 像 Apple 一样防止在桌面上移动

css - 使用 CSS/Flexbox 移动或重新排序父级之外的内容

jquery - 使用 z-index 的 Bootstrap 网格系统重叠

html - Bootstrap : Rows/Cols Layout Issue

html - 具有行和列跨度的 CSS 响应式网格