简体   繁体   English

CSS,显示:表和溢出在子div上无法正常工作

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

Basicly I have a webpage where users can change content inside my layout. 基本上,我有一个网页,用户可以在其中更改布局中的内容。 I'm trying to force the div where the content is being put to overflow hidden or scroll. 我试图迫使内容被放置的div隐藏或滚动溢出。

But the width of my page keeps increasing rather then scrolling/hiding. 但是我页面的宽度一直在增加,而不是滚动/隐藏。

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

Anyone more clever than me that can figure this out? 有比我更聪明的人可以解决这个问题吗? Prolly missing something like position:absolute; Prolly缺少诸如position:absolute;东西position:absolute; or overflow should be somewhere else etc. overflow应该在其他地方等。

Update #container to be display:block; #container更新为display:block; and overflow: scroll; overflow: scroll; . Using display:table; 使用display:table; will make the #container element width as wide as it needs to be to hold the data and will not adhere to the 100% width of the parent element that you have declared and are trying to accomplish. 将使#container元素的宽度与保存数据所需的宽度相同,并且不会遵循已声明并尝试完成的父元素的100%宽度。

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

You should also add height:100%; 您还应该添加height:100%; to your html and body elements if you want the #container element to truly be 100% of the height of the body. 如果您希望#container元素真正是正文高度的100%,请添加到html和body元素。

See Snippet with border added to #container for demonstration purposes. 出于演示目的,请参阅在#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 --> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM