gan*_*esh 3 javascript html5 reactjs bootstrap-4
我是新来的
front-end-development
。现在,这里有下表,
<div className="table-responsive">
<table className="table table-hover" id="job-table">
<thead>
<tr className="text-center">
<th scope="col">Sr.No.</th>
<th scope="col">Company Name</th>
<th scope="col">Technology</th>
<th scope="col">Total Resumes</th>
<th scope="col">Job Title</th>
<th scope="col">Total Score</th>
<th scope="col">Average Score</th>
</tr>
</thead>
<tbody className="text-center">
{this.props.list && this.props.list.content && this.props.list.content.length > 0 && this.props.list.content.map((item, key) => {
return (
<tr key={key}>
<td className="font-weight-bold">1</td>
<td className="font-weight-bold">ABCDED</td>
<td>Software Developer</td>
<td className="font-weight-bold">17</td>
<td>5 years experience</td>
<td className="font-weight-bold">30</td>
<td className="font-weight-bold">30</td>
</tr>
)
})}
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
现在,在此我使用了table-responsive class
。
现在,我尝试通过使用
tbody { height: 400px; overflow-y: scroll }
Run Code Online (Sandbox Code Playgroud)
但这是行不通的。
td
如果内容很大,另一行会受到影响。因此,如何避免这种情况?
谢谢您的帮助。
可以使用设置固定标题position: sticky
。
检查示例代码。
在此设置主容器的高度。
.table-responsive{height:400px;overflow:scroll;}
Run Code Online (Sandbox Code Playgroud)
将位置设置为tr-> th。
thead tr:nth-child(1) th{background: white; position: sticky;top: 0;z-index: 10;}
Run Code Online (Sandbox Code Playgroud)
尝试使用flex,它应该兼容table-responsive
:
table {
display: flex;
flex-flow: column;
width: 100%;
}
thead {
flex: 0 0 auto;
}
tbody {
flex: 1 1 auto;
display: block;
overflow-y: auto;
overflow-x: hidden;
}
tr {
width: 100%;
display: table;
table-layout: fixed;
}
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助
添加display:block
到表中以解决此问题
tbody{height: 400px; overflow-y: scroll;display:block;}
th { position: sticky; top: 0; }
Run Code Online (Sandbox Code Playgroud)
使用位置:粘在顶部:0
th {
background: white;
position: sticky;
top: 0; /* Don't forget this, required for the stickiness */
}
Run Code Online (Sandbox Code Playgroud)
完整的示例可以在这里找到: https ://css-tricks.com/position-sticky-and-table-headers/
归档时间: |
|
查看次数: |
10456 次 |
最近记录: |