Reputation: 923
Too much information how to prevent flex child from growing, but too difficult to find out how to prevent flex PARENT from growing (because of the child).
Consider below layout:
Initial solution:
.layout {
display: flex;
flex-direction: column;
width: 640px;
height: 300px;
background: rgba(220, 20, 60, 0.2);
}
.header {
flex: 0 0 auto;
padding: 4px 8px;
background: rgba(220, 20, 60, 0.2);
}
.content {
display: flex;
flex-direction: column;
flex: 1 1 auto;
padding: 4px 8px;
background: rgba(255, 69, 0, 0.2);
overflow-y: hidden;
}
.title {
flex: 0 0 auto;
background: rgba(255, 255, 0, 0.2);
}
.splitView {
display: flex;
flex: 1 1 auto;
background: rgba(0, 128, 128, 0.2);
overflow-y: hidden;
}
.splitView-section {
display: flex;
flex-direction: column;
flex: 1 1 50%;
}
.splitView-section:first-child {
background: rgba(0, 191, 255, 0.2);
}
.splitView-section:last-child {
background: rgba(0, 0, 255, 0.2);
}
.scrollView {
flex: 1 1 auto;
background: rgba(165, 42, 42, 0.2);
overflow-y: auto;
}
.veryBigElement {
background: #CD5C5C;
width: 50px;
height: 500px;
box-shadow: rgba(0, 0, 0, 0.25) 0 0 6px
}
.footer {
flex: 0 0 auto;
padding: 4px 8px;
background: rgba(173, 255, 47, 0.2);
}
<div class="layout">
<div class="header">I am header</div>
<div class="content">
<div class="title">Title</div>
<div class="splitView">
<div class="splitView-section">
<div class="sectionTitle">Section title</div>
<div class="scrollView">
<div class="veryBigElement"></div>
</div>
</div>
<div class="splitView-section"></div>
</div>
</div>
<div class="footer">I am footer</div>
</div>
width: 640px
and height: 300px;
for instance.flex: 0 0 auto
for header and footer.flex: 1 1 auto
.margin-top: auto
because it is being pressed to bottom by main content.overflow-y: auto
for scroll view.It works. But there is one problem: if we add some elements with shadows (e. g. cards to scroll view), because of overflow-y: hidden
for .splitView
and .content
, we will not see the part of it. E. g. if to add box-shadow: rgba(black, 0.25) 0 0 6px
for .veryBigElement
, we see just:
So, in dependence to design, above solution may not be used. If we remove overflow-y: hidden
from .splitView
and .content
, splitView-section
will grow regardless to overflow-y: auto
for .scrollView
.
Please not that:
.scrollView
's height, even splitView
's height: it could be a lot of contents instead of '.title' in real application.JSFiddle: https://jsfiddle.net/teyqkrh8/
Upvotes: 5
Views: 2768
Reputation: 424
I know it is an old question, but anyway would be useful for others.
Since you don't want to apply some padding to outer container or margin to the shadowed element, you can simply give z-index (greater than any outer elements z-index (if set of course)) property to the shadowed element and it will override cutoffs.
Upvotes: 1
Reputation: 660
If you gave the "veryBigElement" height 500px and you want main content will not be scrolling only inner elements could be scrolled. So you have to add MAX-HEIGHT of veryBigElement parent. If you remove the overflow-y: hidden than splitView-section will not grow.
Upvotes: 0
Reputation: 1384
You can remove "overflow-y: hidden" and add "height: 100%" to .splitView and -section.
.splitView{
display: flex
flex: 1 1 auto
background: rgba(#008080, 0.2)
height: 100%
&-section{
display: flex
flex-direction: column
flex: 1 1 50%
height: 100%
}
}
Since the height of the parent div is set, the children divs will inherit that height.
https://codepen.io/salixdubois/pen/JQLaRE
Upvotes: 1