html - div 内表格的填充

标签 html css

我有如下内容:

.vili_horizontal_scroll_auto{
    width: auto;
    border: solid 1px #bed5cd;
    overflow-x: scroll;
    overflow-y: hidden;
    white-space: nowrap;
}

.vili_table_padding{
    padding-left: 20px;
    padding-right: 20px;
}

table.vili_wide_table {
  width: 1000px;
}

table {
  background-color: coral;
}
<div class="vili_horizontal_scroll_auto vili_table_padding">
  <table class="vili_wide_table">
    <tr><td>this should have whitespace on left and right</td></tr>
  </table>
</div>

<div class="vili_horizontal_scroll_auto vili_table_padding">
  <table>
    <tr><td>this should have whitespace on left and right</td></tr>
    <tr><td>something very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong</td></tr>
  </table>
</div>

问题是表格已正确移动到左侧的空白区域,但即使滚动到最右侧,它仍然会触及右侧的屏幕。

如何修复它,使表格与屏幕端分开。

注意:表格非常宽,所以它几乎总是比屏幕宽。

谢谢

最佳答案

改变你的宽度,它会溢出视口(viewport)。下面的“100%”有效,但我不确定它是否能满足您的需求,但您的问题基本上是 width:1000px;

.vili_horizontal_scroll_auto{
    width: auto;
    border: solid 1px #bed5cd;
    overflow-x: scroll;
    overflow-y: hidden;
    white-space: nowrap;
}

.vili_table_padding{
    padding-left: 20px;
    padding-right: 20px;
}

table {
  width: 100%;
  background-color: coral
}
<div class="vili_horizontal_scroll_auto vili_table_padding">
  <table>
    <tr><td>this should have whitespace on left and right</td></tr>
  </table>
</div>

关于html - div 内表格的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39129627/

相关文章:

html - 用于覆盖图像和 css 模糊的标记和样式

javascript - jquery自动完成运行ajax但不显示结果

html - css - 动态 div 高度

css - 如何让片段在CSS中对齐到顶部

css - IE8 & IE9 渐变使用 -ms-filter 覆盖元素

html - <li> 没有完全着色

html - 列表内的全 Angular 输入和标签

javascript - 如何在我的程序上应用 localStorage 或 javascript Cookie?

html - 实现导航栏问题

CSS 使 li 元素出现在 ul 之外