表格主体部分的滚动属性不起作用
我有一个表,其中标题应固定在其位置并滚动内容。
我找到了滚动它们的方法,方法是使用单独的表使用第一个标题,并使用第二个表来滚动它们,该第二个表位于给定滚动属性的 div 内。
但是,当列数增加时,对齐第一个表中的标题和第二个表中的内容变得困难。
这就是为什么我被迫在 tbody 中创建一个卷轴。但它不起作用。我尝试为 tbody 部分提供滚动属性并固定其高度,但它没有滚动。
我试图纠正的代码是,
<table width="900" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th scope="col">h1</th>
<th scope="col">h2</th>
<th scope="col">h3</th>
<th scope="col">h4</th>
<th scope="col">h5</th>
<th scope="col">h6</th>
</tr>
</thead>
<tbody style="height:5px; overflow:scroll;">
<tr>
<td height="10">1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td height="10">7</td>
<td>8</td>
<td>9</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td height="10">3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td height="10">9</td>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
使用 2 个表创建固定标头的代码是
<table width="900" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th scope="col">h1</th>
<th scope="col">h2</th>
<th scope="col">h3</th>
<th scope="col">h4</th>
<th scope="col">h5</th>
<th scope="col">h6</th>
</tr>
</thead>
</table>
<div style="height:50px; overflow-y:scroll; width:920px;">
<table width="900" border="1" cellspacing="0" cellpadding="0">
<tr>
<td height="10">1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td height="10">7</td>
<td>8</td>
<td>9</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td height="10">3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td height="10">9</td>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
I have a table in which headers should be fixed at their positions and scrolling content.
I found way to scroll them by making first headeing using by a sepparate tables, and body part using a second table which is inside a div which is given scroll property.
But when the number of columns are getting increased, alligning the headings in first table and content in second table is getting difficult.
Thats why I am forced to create a scroll in tbody. But it is not working. I tried to give scroll property to the tbody part and fixed its height, but it is not scrolling.
The code which I am trying to correct is,
<table width="900" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th scope="col">h1</th>
<th scope="col">h2</th>
<th scope="col">h3</th>
<th scope="col">h4</th>
<th scope="col">h5</th>
<th scope="col">h6</th>
</tr>
</thead>
<tbody style="height:5px; overflow:scroll;">
<tr>
<td height="10">1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td height="10">7</td>
<td>8</td>
<td>9</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td height="10">3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td height="10">9</td>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</tbody>
</table>
And the code which creates fixed headers using 2 tables is
<table width="900" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th scope="col">h1</th>
<th scope="col">h2</th>
<th scope="col">h3</th>
<th scope="col">h4</th>
<th scope="col">h5</th>
<th scope="col">h6</th>
</tr>
</thead>
</table>
<div style="height:50px; overflow-y:scroll; width:920px;">
<table width="900" border="1" cellspacing="0" cellpadding="0">
<tr>
<td height="10">1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td height="10">7</td>
<td>8</td>
<td>9</td>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td height="10">3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
<tr>
<td height="10">9</td>
<td>0</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这样
try it like this