简体   繁体   English

Flex子元素超出父容器元素,并具有溢出滚动

[英]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.

相关问题 当父容器元素具有溢出滚动时,这是否可以使子 dom 元素具有可见的溢出? - Is this possible to make the child dom element to have visible overflow when parent container element has overflow scroll? 溢出:在 go 离开其父级的元素上滚动 - overflow: scroll on an element that go out of his parent Flex 子项无法在 Flex 容器上使用滚动溢出 - Flex child not working with scroll overflow on flex container 在 TailwindCSS 中,为什么我的 flex-1 元素会溢出父元素的高度,即使我在溢出的子元素中使用了overflow-y-scroll? - In TailwindCSS, why is my flex-1 element overflowing the height of the parent element, even though I use overflow-y-scroll in the overflowing child? 位置绝对与 Left:100% ,子元素离开父容器 - Position absolute with Left:100% , Child element goes out of the parent continer 粘性元素到父溢出容器 - Sticky element to parent overflow container Flex 子元素的大小超出其父定义的大小 - Flex child element is growing out of its parent defined size 如何使用 overflow-x 保持子元素:滚动改变父元素的宽度 - How to keep child element with overflow-x: scroll from changing the width of parent element 将父级滚动到子元素的顶部 - Scroll parent to top of child element :scroll元素的最大宽度,以匹配flex-grow父元素的宽度 - max-width of overflow:scroll element to match flex-grow parent elements width
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM