是否有一种方法可以将水平滚动条添加到HTML表中?我实际上需要它是可滚动的,垂直和水平取决于表如何增长,但我不能得到任何滚动条出现。
当前回答
为div元素添加标签表,style="overflow-x:auto"
<div style="overflow-x:auto">
<table class="table table-bordered">
<thead>
<tr>
<th><b>Name</b></th>
<th><b>Username</b></th>
<th><b>Email</b></th>
<th><b>Avatar</b></th>
<th><b>Status</b></th>
<th><b>Action</b></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
其他回答
.wrapper {
width: 0;
min-width: 100%; //width 0, but min-width 100?? yes, I know...
overflow: auto;
}
<div class="wrapper">
<table></table>
</div>
表可以有任何宽度。我通常使用100%或max-content作为表。
为div元素添加标签表,style="overflow-x:auto"
<div style="overflow-x:auto">
<table class="table table-bordered">
<thead>
<tr>
<th><b>Name</b></th>
<th><b>Username</b></th>
<th><b>Email</b></th>
<th><b>Avatar</b></th>
<th><b>Status</b></th>
<th><b>Action</b></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
与引导
<div class="table-responsive">
<table class="table">
...
</table>
</div>
这解决方案似乎有点过头了。最简洁的方法是像这样用div来包装:
<div style="overflow-x:auto;">
<table>
...
</table>
</div>
https://www.w3schools.com/howto/howto_css_table_responsive.asp
这是对Serge Stroobandt的答案的改进,效果非常好。它解决了表没有填充整个页面宽度的问题,如果它有较少的列。
<style>
.table_wrapper{
display: block;
overflow-x: auto;
white-space: nowrap;
}
</style>
<div class="table_wrapper">
<table>
...
</table>
</div>
推荐文章
- 向HTML表中添加水平滚动条
- 在notepad++中格式化代码
- 表单中包含表单,可以吗?
- 如何创建表只使用<div>标签和Css
- html5 - canvas元素-多层
- 如何确保<select>表单字段被禁用时提交?
- 如何在HTML文本换行?
- 如何在JavaScript中转义单引号(')?
- Chrome开发工具:如何找出什么是覆盖CSS规则?
- 如何使用HTML/CSS在文本中插入空格/制表符
- 用背景图像填充SVG路径元素
- 将JSON显示为HTML
- HTML被认为是一种编程语言吗?
- 如何修复favicon.ico错误:“Failed to load resource: net::ERR_EMPTY_RESPONSE”
- 大Glyphicons