gpt4 book ai didi

javascript - 表格标题未占据页面的整个宽度

转载 作者:行者123 更新时间:2023-12-02 23:32:23 25 4
gpt4 key购买 nike

您好,下面您可以看到我的表格,但是,它没有占据页面的整个宽度,我相信这与我的内容有关

 <div style={{ overflow: 'auto', height: '250px' }}> 

但是,我需要将表格标题保留在页面内,并且不允许与表格主体一起向下滚动

最佳答案

该解决方案在 Chrome 中完美运行。这在 IE 中不起作用。 Refer here for more solutions that work with Javascript and jQuery that works for IE

    table thead tr th {
position: -webkit-sticky;
position: sticky;
background-color: white;
z-index: 100;
top:-1px;
}

table {
border-collapse: collapse;
width: 100%;
}

td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}

tr:nth-child(even) {
background-color: #dddddd;
}

table thead tr th {
background-color: white;
position: sticky;
z-index: 100;
top: -1px;
}
<table>
<thead>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>Giovanni Rovelli</td>
<td>Italy</td>
</tr>
</tbody>
</table>

关于javascript - 表格标题未占据页面的整个宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56442479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com