HTML固定标题-将位置th与td在同一级别上对齐
HTML Fixed header - Align position th at the same level as td
我创建了一个具有固定标题和滚动的表。它工作得很好,但表头对齐与表数据不匹配。我的意思是,结果应该是
--------------------
Id Heading2 Heading3
--------------------
1 value1 value2
2 value1 value2
3 value1 value2
但在我的表中,表头与表数据不匹配,这意味着表头没有正确对齐。这是我的小提琴。我试过padding
。但它没有起作用。所以,请帮助如何对齐标题以匹配相应的列?JQuery和Javascript解决方案也是可以接受的。
试试这个css:
thead >tr,th
{
border:none;
padding:5px 20px 5px 10px;
text-align: center;
background-color:#0B3B17;
font-size:12pt;
}
td
{
border:none;
color:#61210B;
text-align: center;
padding: 3px 5px;
}
table
{
display: block ;
height: 100px;
overflow-y: scroll;
width:400px;
background-color: #ddd;
}
试试这个:
html:
<table>
<thead>
<tr>
<th class="id">Id</th>
<th>Name</th>
<th>Job</th>
</tr>
</thead>
<tbody>
<tr>
<td class="id">1</td>
<td class="name">Raja</td>
<td class="position">developer</td>
</tr>
<tr>
<td class="id">2</td>
<td class="name">Rajesh</td>
<td class="position">associate consultant</td>
</tr>
<tr>
<td class="id">2</td>
<td class="name">Rajesh</td>
<td class="position">associate consultant</td>
</tr>
<tr>
<td class="id">2</td>
<td class="name">Rajesh</td>
<td class="position">associate consultant</td>
</tr>
<tr>
<td class="id">2</td>
<td class="name">Rajesh</td>
<td class="position">associate consultant</td>
</tr>
</tbody>
</table>
css:
thead tr th
{
color:red;
text-align:center;
width:100px;
}
tbody
{
position: absolute;
height: 100px;
overflow: scroll;
background-color:red;
}
tbody tr td
{
width:100px;
}
.id
{
text-align:right;
}
.name, .position
{
text-align:center;
}
相关文章:
- jquery移动对齐按钮取决于内容大小
- 如何在JavaScript图像滑块内居中对齐图像
- 为什么文本对齐:对;工作不正常
- 显示可链接的搜索结果+对齐方式
- 以Jquery为中心的Div中的图像对齐
- 无法将文本与图片垂直对齐
- 在这种情况下,如何正确对齐显示
- 使用jquery垂直对齐动态加载的图像
- 如何使 DIV 中的内容垂直对齐
- '填隙'当所述项目不在容器中时,将一些项目与引导程序网格对齐
- typeahead下拉结果向右对齐-向右拉
- css中的按钮对齐
- Wordpress 3级水平导航-需要jquery/javascript帮助进行对齐
- 嵌入的Vimeo与中心对齐
- HighMaps:在图例中对齐ColorAxis
- jqPlot对齐不同y轴的零
- 将两个图形(饼图和条形图)并排对齐::d3-js
- html根据DIRECTION设置更改元素的水平对齐
- 对齐底部的DIV-谷歌Chrome扩展
- jquery对话框内容仅针对第一个请求进行对齐