[英]Flex child element goes out of parent container element with overflow scroll
How can I get the main-content
to shrink from the right rather than going behind the sidebar? 如何使
main-content
从右侧收缩而不是在侧边栏后面? Not sure flexbox is needed for what I'm trying to do but it's almost working.. 不确定我想做的事情是否需要flexbox,但是它几乎可以正常工作。
https://codepen.io/anon/pen/qJJeMr https://codepen.io/anon/pen/qJJeMr
html, body { margin: 0; } .container { position: fixed; height: 100%; width: 100%; } .row { height: 100%; display: flex; } .main-content { background: white; height: 100%; flex: auto; display: flex; justify-content: center; align-items: center; white-space: nowrap; overflow-x: auto; } .main-content .content { background: lightgreen; padding: 10px; margin: 10px; height: 300px; display: flex; min-width: 720px; } .sidebar { background: #f2f2f2; height: 100%; width: 700px; flex: none; display: flex; } .sidebar .side-menu-bar { height: 100%; width: 80px; background: lightcyan; flex: none; }
<div class="container"> <div class="row"> <div class="sidebar"> <div class="side-menu-bar"></div> <div class="side-content-panel"></div> </div> <div class="main-content"> In main container, outside main content... <div class="content"> This is the main content. </div> </div> </div> </div>
It's not shrinking as you want, and overlapping its sibling element, because it has a fixed minimum width. 它并没有按照您的要求收缩,而是与其同级元素重叠,因为它具有固定的最小宽度。
.main-content .content {
background: lightgreen;
padding: 10px;
margin: 10px;
height: 300px;
display: flex;
min-width: 720px; <----- HERE
}
The main content on the right is not shrinking since you have given a min-width:720px;
右边的主要内容没有缩小,因为您指定了
min-width:720px;
for .content
, Once you remove that, your issue will be fixed. 对于
.content
,将其删除后,您的问题将得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.