首页 > 解决方案 > 多头时如何制作表格的粘性表头

问题描述

我正在尝试使表格的标题具有粘性。但这似乎不起作用。这个实验我一直在尝试使用流星框架。

                         <table class="tableclass">
                            <thead class="headclass">
                            <tr class="tr">
                                <th style="color: #ffffff">th content</th>

                                {{#each names}}
                                    <th>{{name}}</th>
                                {{/each}}
                            </tr>
                            </thead>

                            {{#each peoples}}
                                <thead>
                                <tr class="tr-another">
                                    <th  colspan="100%">
                                   <span id="report"><img id="icons" src="button.svg" width="16px" height="16px">
                                   </span> {{this}}</th>
                                </tr>
                                </thead>
                                <tbody class={{this}}>
                                {{>Field}}
                                </tbody>
                            {{/each}}

                        </table>

我使用了以下样式。

tableclass{
    overflow-y: auto;
    height:100px;
    }

.outer table{
    width: 100%;
    table-layout: fixed;
    border : 1px solid black;
    border-spacing: 1px;
}

.outer table th {
        text-align: left;
        top:0;
        position: sticky;
        background-color: white;  
}

有人可以帮忙吗?我想让第一个主题变得粘稠。

谢谢。

标签: javascripthtmlcssformsmeteor

解决方案


根据css-tricks.com,您不能设置也不能设置position: sticky;. 但你可以粘一个。这很奇怪,但它有效。<thead><tr><th>

您在类上设置此属性.outer table th。但我没有在你的 HTML 中看到这个类!

实际上,根据您的 HTML 代码,您可以这样写:

.headclass th {
  position: sticky;
  top: 0;
}


推荐阅读