Is it possible to make a flex element ignore a child element so it's size does not affect the other elements?
For example, I have a wrapper with display: flex
. It has a header, content, and footer.
<div class="wrapper"> <header></header> <article></article> <footer></footer> </div>
I want the wrapper to ignore the header tag (the header will be fixed to the top of the window). The article will be set to flex: 1
so it takes up the rest of the space, forcing the footer to the bottom of the page. Here is some sample CSS:
.wrapper { display: flex; flex-direction: column; height: 100%; padding-top: 50px; /* Accounts for header */ } header { height: 50px; position: fixed; top: 0; width: 100%; } article { flex: 1; } footer { height: 50px; }
I know I could just move the header outside of the wrapper but I have a lot of existing code that will make that a bit more difficult. Is what I am asking even possible?
Heights equalised within a row.
When you enable the flex display setting for a parent element, the children align left and stack horizontally by default. Flex containers will not affect or change the layout of the children within their direct, child elements.
The display property is not inherited, so display: flex is not either.
It's all about the children Flexbox is different from many other CSS properties: instead of targeting an element and acting directly upon it, we target the parent element and that controls the layout of its children. We're making a flex container and all the children of that container become flex items.
In your .wrapper declare flex-wrap: wrap
. Then for your header, you can add the style flex-basis: 100%
which will force everything else down below the header.
Use position: absolute
for the child element to exclude it from the flex calculations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With