【发布时间】:2019-04-06 09:24:49
【问题描述】:
我正在尝试修复表格的标题,使其不会滚动但保持固定。
我搜索了一些较旧的 SO 线程,试图找到修复可滚动表标题的解决方案。我对 bootstrap 和 React 还很陌生,我相信我已经很接近了。我在这里问这个问题是为了找到特定于我的代码的答案。
我在反应组件中的表
<div>
<div className="tablediv">
<div className="table-wrapper-scroll-y my-custom-scrollbar">
<table className="table table-hover table-striped table-light">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Date</th>
<th scope="col">Value: USD</th>
</tr>
</thead>
<tbody>
{priceAndDateArray.slice(0).reverse().map((item, i) => (
<tr key={i}>
<th scope="row">{i+1}</th>
<td>{item.date}</td>
<td>{item.price}</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
我与表格相关的 css
.tablediv {
flex-wrap: wrap;
align-content: space-evenly;
padding: 5%;
justify-content: center
}
.tablediv tr {
cursor: pointer;
cursor: hand;
}
.my-custom-scrollbar {
position: relative;
height: 400px;
overflow: auto;
}
.table-wrapper-scroll-y {
display: block;
}
预期结果是表的顶部标题(#、日期、值:美元)要固定到位。实际结果是它们随表格滚动。
【问题讨论】:
标签: css reactjs bootstrap-4 fixed-header-tables