Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html表格中的最大高度_Html_Css - Fatal编程技术网

Html表格中的最大高度

Html表格中的最大高度,html,css,Html,Css,我创建了一个表,我希望它的高度是heightbe800px 如果它溢出,我想使滚动条,但标题不滚动 因此,我尝试添加以下CSS: overflow: scroll; max-height:800px; 但这对我不起作用。这是整个html文件。有什么问题 CSS 和HTML <table > <tr> <th>field a</th> <th>field b</th> <th>field c

我创建了一个表,我希望它的高度是
height
be
800px

如果它溢出,我想使滚动条,但标题不滚动

因此,我尝试添加以下CSS:

overflow: scroll;
max-height:800px;
但这对我不起作用。这是整个html文件。有什么问题

CSS

和HTML

<table >
  <tr>
   <th>field a</th>
   <th>field b</th>
   <th>field c</th>
   <th>field e</th>
  </tr>
  <tr>
   <td>3534534</td>
   <td>עו"ש</td>
   <td>6,463</td>
   <td>4,000</td>
  </tr>
  <tr>
   <td>3534534</td>
   <td>עו"ש</td>
   <td>6,463</td>
   <td>4,000</td>
  </tr>
</table>

场a
b区
字段c
场e
3534534
עו"ש
6,463
4,000
3534534
עו"ש
6,463
4,000

谢谢

使用另一个元素包装整个表,并将这些属性提供给他:

#table-limiter {
max-height:800px;
overflow: scroll;
}
HTML示例:

<div id="table-limiter">
   <table>
      ...
   </table>
</div>

...

设置表格样式有时是一个麻烦:(

您可以将表格包装在一个div中,并将
最大高度设置为
溢出:滚动到该div


场a
b区
字段c
场e
3534534
עו"ש
6,463
4,000
...
.pane{
显示:内联块;
溢出y:滚动;
最大高度:200px;
}
桌子{
文本对齐:居中;
保证金:自动;
}

在没有包装器div的情况下,还有另一个解决方案,但是在行的周围有一个额外的
thead
tbody
。您可以将thead和tbody设置为
display:block
,并给tbody一个
max height
overflow-y
。这样可以在滚动行时使页眉保持原位。但与往常一样,我t带有一个价格标签。您必须指定列宽,因为由于
display:block


场a
b区
字段c
场e
3534534
עו"ש
6,463
4,000
...
thead{
显示:块;
}
t车身{
显示:块;
溢出y:滚动;
最大高度:200px;
}
thead th,tbody td{
宽度:70px;
}

更新:

在该网站的源代码中,有关于IE和IE6的评论

thead tr {
    position: relative
}
并使用

table {
    float: left;
    width: 740px
}
我不知道这是否与IE10相关。

这里有一种方法

使用CSS添加换行div:

#set-height {
    display: inline-block;
    height:800px;
    overflow: scroll;
}

Fiddle:

用div标记将表格包装起来,并将div的高度设置为800px,溢出设置为auto

<div style="height:800px; overflow:auto;">
//Table goes here
</div>

//桌子在这里

然后,如果您的表格高度超过800px,则div中将显示一个滚动条,允许您在表格中滚动。

将此应用于父元素是否要使表格行可滚动,但其上方仍有列标题?您好,这很好。但我希望在滚动时标题保持在顶部。我该怎么做?谢谢!我帮你看了一下,并更新了固定单元格的宽度:谢谢!这在谷歌Chrome中对我有用。(与JSFIDLE风格相同)但不是在IE10中。有解决方案吗?我没有IE10,所以我不能说。当你查看该站点的源代码时,会有关于IE6的评论。请参阅更新的答案。仅供参考,第二个选项不适用于使用百分比定义的列宽。但是
em
rem
vw
似乎对jsfiddl很有效例如,在这种情况下,如何将表格拉伸到100%,并保持每列的宽度相等(25%)@Felix您可以同时尝试表格和包装
width:100%;
,对于
th,td
give
width:25%;
<div style="height:800px; overflow:auto;">
//Table goes here
</div>