首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >100%宽度的HTML表格,正文内有垂直滚动

100%宽度的HTML表格,正文内有垂直滚动
EN

Stack Overflow用户
提问于 2013-06-12 21:50:42
回答 7查看 941.1K关注 0票数 461

如何将<table>设置为100%宽度,并仅在<tbody>垂直滚动中设置一定的高度?

table {
    width: 100%;
    display:block;
}
thead {
    display: inline-block;
    width: 100%;
    height: 20px;
}
tbody {
    height: 200px;
    display: inline-block;
    width: 100%;
    overflow: auto;
}
<table>
  <thead>
    <tr>
    	<th>Head 1</th>
    	<th>Head 2</th>
    	<th>Head 3</th>
    	<th>Head 4</th>
    	<th>Head 5</th>
    </tr>
  </thead>
  <tbody>
    <tr>
    	<td>Content 1</td>
    	<td>Content 2</td>
    	<td>Content 3</td>
    	<td>Content 4</td>
    	<td>Content 5</td>
    </tr>
  </tbody>
</table>

我想避免添加一些额外的div,所有我想要的是像这样的简单的表格,当我试图改变显示,table-layoutposition和更多的东西在CSS表不好与100%宽度只与固定宽度的px。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17067294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档