html - 100% 的内部滚动框不是 View 框

标签 html css kendo-grid

100% 可滚动容器中的元素计算为 View 框的 100% 而不是实际大小。

你可以看到问题in this Codepen并在以下代码段中:

#container {
  max-width: 25em;
  background: #181818;
  overflow-x: auto;
}
#container #main td {
  background: #646464;
  white-space: nowrap;
  height: 5em;
}
#container #bottom {
  position: releative;
  width: 100%;
  height: 2em;
  background: #cdc;
}
#container #bottom span:first-child {
  float: left;
}
#container #bottom span:last-child {
  float: right;
}
<div id="container">
  <table id="main">
    <tbody>
      <tr>
        <td>1111111</td>
        <td>2222222</td>
        <td>3333333</td>
        <td>4444444</td>
        <td>5555555</td>
        <td>6666666</td>
        <td>7777777</td>
        <td>8888888</td>
        <td>9999999</td>
      </tr>
    </tbody>
  </table>
  <div id="bottom">
    <span>0%</span>
    <span>100%</span>
  </div>
</div>

what i see

我想要这个:

what i want

编辑:
真正的问题是关于 Kendo grid,所以我无法更改它的模板。

最佳答案

不修改HTML

我认为最简单的解决方案是删除 #bottom 宽度并使用 Javascript 检索 #main 的宽度并将其应用于 #bottom

Javascript

//Create "tableWidth" variable from width of #main
var tableWidth = document.getElementById('main').offsetWidth;

//Set width of #bottom
document.getElementById('bottom').style.width = tableWidth+'px';

结果

Screenshot

示例演示

还有 applied to your Codepen.

//Create "tableWidth" variable from width of #main
var tableWidth = document.getElementById('main').offsetWidth;

//Set width of #bottom
document.getElementById('bottom').style.width = tableWidth+'px';
#container {
  max-width: 25em;
  background: #181818;
  overflow-x: auto;
}
#container #main td {
  background: #646464;
  white-space: nowrap;
  height: 5em;
}
#container #bottom {
  position: releative;
  height: 2em;
  background: #cdc;
}
#container #bottom span:first-child {
  float: left;
}
#container #bottom span:last-child {
  float: right;
}
<div id="container">
  <table id="main">
    <tbody>
      <tr>
        <td>1111111</td>
        <td>2222222</td>
        <td>3333333</td>
        <td>4444444</td>
        <td>5555555</td>
        <td>6666666</td>
        <td>7777777</td>
        <td>8888888</td>
        <td>9999999</td>
      </tr>
    </tbody>
  </table>
  <div id="bottom">
    <span>0%</span>
    <span>100%</span>
  </div>
</div>

旧答案

将 span 放在具有 colspan="9" 且样式为 tfoot td 的 tfoot td 中。将现有的 td 属性应用于 tbody td

例子

还有 applied to your Codepen

#container {
  max-width: 25em;
  background: #181818;
  overflow-x: auto;
}
#container #main tbody td {
  background: #646464;
  white-space: nowrap;
  height: 5em;
}
tfoot td {
  height: 2em;
  background: #cdc;
}
tfoot span:first-child {
  float: left;
}
tfoot span:last-child {
  float: right;
}
<div id="container">
  <table id="main">
    <tbody>
      <tr>
        <td>1111111</td>
        <td>2222222</td>
        <td>3333333</td>
        <td>4444444</td>
        <td>5555555</td>
        <td>6666666</td>
        <td>7777777</td>
        <td>8888888</td>
        <td>9999999</td>
      </tr>
    </tbody>
    <tfoot>
      <tr>
        <td colspan="9">
          <span>0%</span>
          <span>100%</span>
        </td>
      </tr>
    </tfoot>
  </table>
</div>

关于html - 100% 的内部滚动框不是 View 框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26365267/

相关文章:

javascript - iframe 中的 PDF 已缓存

html - 我不能在输入标签之间放置空格

asp.net-mvc - 如何使用 Kendo UI 网格打开其中包含列表的模式

html - 创建静态菜单 CSS

jquery - 使用 CSS 调整可调整大小图像的图像描述栏

css - 如何在不缩放边框宽度的情况下缩放(变换)div的宽度和高度?

kendo-grid - Kendo 网格列可过滤模式 : "Row" and "Menu"

javascript - Kendo Grid 删除事件的自定义警报

javascript - Jquery slideUp 在第一次点击时不起作用

css - 当鼠标悬停在芒果上时,我想显示绿色的苹果而不是红色的芒果