Hello fellow programmers!
I've got a simple box-layout which I would love to achieve using flexbox, but I simply can't figure it out. It should look like this image.
So basically a row and two columns, with the row being fixed at lets say 100px in height, but all in one container. My code so far is:
#productShowcaseContainer {
display: inline-flex;
flex-flow: row wrap;
height: 600px;
width: 580px;
background-color: rgb(240, 240, 240);
}
#productShowcaseTitle {
display: inline-block;
height: 100px;
width: 100%;
background-color: rgb(200, 200, 200);
}
#productShowcaseDetail {
flex: 3;
background-color: red;
}
#productShowcaseThumbnailContainer {
flex: 2;
background-color: blue;
}
<div id="productShowcaseContainer">
<div id="productShowcaseTitle"></div>
<div id="productShowcaseDetail"></div>
<div id="productShowcaseThumbnailContainer"></div>
</div>
I know this can be achieved in many ways, but I would really prefer to use CSS Flex.
You've almost done it. However setting
flex: 0 0 <basis>
declaration to the columns would prevent them from growing/shrinking; And the<basis>
parameter would define the width of columns.In addition, you could use CSS3
calc()
expression to specify theheight
of columns with the respect to the height of the header.(Vendor prefixes omitted due to brevity)
Alternatively, if you could change your markup e.g. wrapping the columns by an additional
<div>
element, it would be achieved without usingcalc()
as follows:(Vendor prefixes omitted due to brevity)
This is copied from above, but condensed slightly and re-written in semantic terms. Note:
#Container
hasdisplay: flex;
andflex-direction: column;
, while the columns haveflex: 3;
andflex: 2;
(where "One value, unitless number" determines theflex-grow
property) per MDNflex
docs.Just use another container to wrap last two divs. Don't forget to use CSS prefixes.