CSS、显示:table 和溢出在 child div 上无法正常工作

CSS, display: table and overflow not working properly on child div's

基本上我有一个网页,用户可以在其中更改我的布局中的内容。我试图强制 div 内容被放置溢出隐藏或滚动。

但是我的页面宽度一直在增加,而不是 scrolling/hiding。

http://jsfiddle.net/weLn0g96/3/

有比我聪明的人能解决这个问题吗? Prolly 遗漏了 position:absolute;overflow 之类的东西应该在其他地方等

#container 更新为 display:block;overflow: scroll;。使用 display:table; 将使 #container 元素的宽度与保存数据所需的宽度一样宽,并且不会遵守您已声明并试图实现的父元素的 100% 宽度。

#container {
  /* Change display: table; to */ display: block;
  width: 100%;
  height: 100%;
  text-align:center;
  overflow: scroll; /* add this */
}

如果您希望 #container 元素真正达到 body 高度的 100%,您还应该将 height:100%; 添加到 html 和 body 元素。

为了演示目的,请参阅添加了边框的代码段 #container

html,
body {
  margin: 0;
  padding: 0;
  background-color: #111111;
}

#container {
  /* Change display: table; to */
  display: block;
  width: 100%;
  height: 100%;
  text-align: center;
  overflow: scroll;
  /* add this */
}

#container {
  /* styles just for demonstration */
  border: 5px solid green;
  box-sizing: border-box;
}

#row-empty {
  display: table-row;
  width: 100%;
  height: 100%;
}

#sides {
  display: table-cell;
}

#main {
  display: table-cell;
  width: 800px;
  margin: 0px;
  padding: 0px;
}

#main-table {
  display: table;
  width: 100%;
  height: 100%;
  background-color: #CCCCCC;
}

#menu {
  display: table-row;
}

#menu-col {
  display: table-cell;
  width: 100%;
  height: 100px;
  border-bottom: 1px solid #000000;
}

#page {
  display: table-row;
  width: 100%;
  height: 100%;
}

#page-col {
  display: table-cell;
  position: relative;
  background-color: yellow;
  overflow-x: hidden;
}
<div id="container">
  <div id="row-empty">

    <div id="sides">&nbsp;</div>
    <!-- Left Column -->

    <div id="main">
      <!-- Middle Column -->

      <div id="main-table">
        <!-- New table inside table-cell for rows inside this cell -->

        <div id="menu">
          <!-- Top Row -->
          <div id="menu-col">

            menu

          </div>
        </div>

        <div id="page">
          <div id="page-col">
            <!-- Middle Row -->

            testar [asdf] asdasd
            <div news style="display:inline-block;width:500px;overflow-x:auto;background-color:red;width:1500px;">Inga nyheter än.</div> xx

          </div>
        </div>

      </div>

    </div>
    <!-- Middle Column (main) end -->

    <div id="sides">&nbsp;</div>
    <!-- Right Column -->

  </div>
  <!-- row end -->
</div>
<!-- container end -->