CSS Flexbox - various height of elements on a wrapper

I have a simple layout with various size elements that I am trying to assemble for a toolbar.

div { padding: 5px 5px 5px 5px; margin: 1px 1px 1px 1px; display: flex; } div.first { border: 1px dotted lightpink; } div.second { border: 1px dotted orange; } div.third { border: 1px dotted green; } div.fourth { border: 1px dotted fuchsia; } 
 <div style="display: flex; height: 500px"> <div class="first" style="flex: 0 60%;flex-wrap: wrap;align-items;stretch;align-content:stretch"> <div class="first" style="flex: 1 100%; align-self: flex-start"> Title text </div> <div class="second" style="flex: 2 auto"> Content A </div> <div class="third" style="flex: 1 auto"> Content B </div> <div class="fourth" style="flex: 1 auto"> <div style="height: 66px; align-self:flex-end"> <div style="align-self: flex-end"> Content C </div> </div> </div> </div> <div class="second" style="flex: 1 auto; align-items: flex-end"> Content D </div> </div> 

Codepen link: http://codepen.io/korgmatose/pen/qqKzry?editors=1100

I want to fill in the second line (Content A, B, C) so that it starts only under the heading text.

But creating align-items flex-start will not allow the second line to fill the remaining space, and setting height to 100% on one of the elements in this line sets only the height of the parent container, thus making the div outside the bottom of the border.

+5
source share
2 answers

As @kukkuz said, I also recommend doing it this way. Just put the contents of A, B, C in a separate container, in this case #content and add display: flex , flex-direction: column and flex: 1 to it, and don't use the inline style to style your HTML, as it does your code less understood. The most recommended way is to add CSS code to a separate file and link it with your HTML.

The following code is an example of how you could layout your desired layout without any inline styles.

HTML

 <div id="wrapper"> <div class="left"> <div class="title">Title text</div> <div id="content"> <div class="second">Content A</div> <div class="third">Content B</div> <div class="fourth">Content C</div> </div> </div> <div class="right">Content D</div> </div> 

CSS

 div { padding: 5px 5px 5px 5px; margin: 1px 1px 1px 1px; } #wrapper { display: flex; height: 500px; } .left { flex: 3; display: flex; flex-direction: column; } #content{ flex: 1; display: flex; padding: 0; } .second, .third, .fourth { flex: 1; } .third { border: 1px dotted green; } .fourth { display: flex; align-items: flex-end; border: 1px dotted fuchsia; } .right { flex: 2; } .left, .title { border: 1px dotted lightpink; } .right, .second { border: 1px dotted orange; } 

 div { padding: 5px 5px 5px 5px; margin: 1px 1px 1px 1px; } #wrapper { display: flex; height: 500px; } .left { flex: 3; display: flex; flex-direction: column; } #content { flex: 1; display: flex; padding: 0; } .second, .third, .fourth { flex: 1; } .third { border: 1px dotted green; } .fourth { display: flex; align-items: flex-end; border: 1px dotted fuchsia; } .right { flex: 2; } .left, .title { border: 1px dotted lightpink; } .right, .second { border: 1px dotted orange; } 
 <div id="wrapper"> <div class="left"> <div class="title">Title text</div> <div id="content"> <div class="second">Content A</div> <div class="third">Content B</div> <div class="fourth">Content C</div> </div> </div> <div class="right">Content D</div> </div> 
+4
source

 div { padding: 5px 5px 5px 5px; margin: 1px 1px 1px 1px; display: flex; } div.first { border: 1px dotted lightpink; } div.second { border: 1px dotted orange; } div.third { border: 1px dotted green; } div.fourth { border: 1px dotted fuchsia; } 
 <div style="display: flex;"> <div class="first" style="flex: 0 60%;flex-wrap: wrap;align-items;stretch;align-content:stretch"> <div class="first" style="flex: 1 100%; align-self: flex-start"> Title text </div> <div class="second" style="flex: 2 auto"> Content A </div> <div class="third" style="flex: 1 auto"> Content B </div> <div class="fourth" style="flex: 1 auto"> <div style="height: 66px; align-self:flex-end"> <div style="align-self: flex-end"> Content C </div> </div> </div> </div> <div class="second" style="flex: 1 auto; align-items: flex-end"> Content D </div> </div> 

Something like that?

0
source

Source: https://habr.com/ru/post/1261033/


All Articles