我需要一个带有可滚动正文的固定表头.我已经尝试了所有方法,但它似乎不起作用
I need a fixed table header with a scrollable body. I have tried everything but it won't seem to work
<!DOCTYPE html>
<html>
<link href="../../../CSS/StatePage.css" rel="stylesheet" type="text/css">
<script src="sorttable.js"></script>
<header>
<h1>
<a href="../../OpenPage.html"> <img src="../../logo.jpg" alt="logo" width="30" height="30"/></a>Title</h1>
<h6>small header</h6>
</header>
<br> <br>
<br> <br>
<br>
<div>
<table id="states"
align="center"
class="sortable"
>
<thead>
<tr>
<th><h4>Table title 1</h4></th>
<th><h4>Table title 2</h4></th>
<th><h4>Table title 3</h4></th>
</tr>
</thead>
<tbody>
<tr>
<td>Name</td>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td>Name</td>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td>Name</td>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td>Name</td>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td>Name</td>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td>Name</td>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td>Name</td>
<td>Name</td>
<td>Date</td>
</tr>
<tr>
<td>Name</td>
<td>Name</td>
<td>Date</td>
</tr>
</tbody>
</table>
</div>
<footer>
<h2> Footer Name </h2>
</footer>
</html>
///////这是我的 CSS
h1, h2, h6 {
font-family: Helvetica;
text-align: center;
}
header {
background-color: #FFFFFF;
position: fixed;
width: 100%;
top: 0px;
border-bottom: solid;
height: 99px;
}
tr, td {
padding: 5px;
}
table {
margin-top: 5px;
}
/* Sortable tables */
table.sortable thead {
background-color: #eee;
color: #E5855F;
cursor: default;
}
tr:nth-child(even) {
background-color: #FFC792;
}
thead {
font-family: Helvetica;
text-align: left;
}
tbody {
overflow: auto;
}
a:link {
color: black;
}
footer {
background-color: #FFFFFF;
position: fixed;
width: 100%;
top: auto;
bottom: 0px;
border-top: solid;
}
如果将
thead 和 tbody 的显示属性设置为"内联块",则会滚动。可能不是你所需要的,但你必须把它弄成一周。
此外,您还必须将表包装在容器div 中,这样元素就不会"掉出来">
thead {
width: 290px;
display: inline-block;
}
tbody {
width: 290px;
display: inline-block;
height: 70px;
overflow-y: scroll;
}
table {
margin-top: 5px;
}
tbody {
overflow-y: scroll;
}
#table-cont {
width: 290px;
}
https://jsfiddle.net/m12x44mo/1/
相关文章:
- Meteor-添加用户自定义字段的方法不起作用
- 在 JQUERY 中创建 HTML 后,Jquery 方法不起作用
- 为什么这个扩展方法不起作用
- Splice()方法不起作用
- Angularjs-向工厂传递数据的方法不起作用
- 我试图使用引导模式类来制作一个弹出注册表单,但弹出没有'不起作用
- Knockout和bread.js的take方法不起作用Paging
- javascript注入$http-post方法不起作用
- 为什么pulk()和where()方法不起作用
- Ajax get 方法不起作用
- 当我将javascript代码放在外部站点.js文件中时,Ajax页面方法不起作用
- getJSON 方法不起作用
- Jquery ajax get 方法不起作用
- jQuery AddClass 方法不起作用
- ScriptManager.RegisterStartupScript() 方法不起作用 - ASP.NET,C#
- 为什么JavaScript方法不起作用
- 为什么 findRandom() mongoose for node.js 方法不起作用
- BackboneJS的设置方法不起作用
- 从javascript调用 asp.net 页面方法不起作用
- 主干.js对以前的方法不起作用进行建模