I have 3 divs vertically stacked in container. I want middle div to be centered but continue expanding horizontally as much as it can but less than max-width. Just like normal div would with max-width without flexbox involved.
https://codepen.io/anon/pen/XaQXOW
css
.cont {
display: flex;
flex-direction: column;
}
.b {
max-width: 500px;
background-color: cyan;
}
.a, .b, .c {
border: 1px solid #000;
height: 100px;
}
html
<div class="cont">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
</div>
position:fixed makes flexbox not workable, since it overrides the position of <p>Hello</p> Try to remove it and see the difference. If you want align-items:center works; try to set height: 100vh; since the body height of webview is not set to screen height by default.
display. This defines a flex container; inline or block depending on the given value. It enables a flex context for all its direct children. Note that CSS columns have no effect on a flex container.
Set align-self: center;
to center your div and add width: 100%
:
.cont {
display: flex;
flex-direction: column;
}
.b {
max-width: 500px;
background-color: cyan;
align-self: center;
width: 100%;
box-sizing: border-box;
}
.a, .b, .c {
border: 1px solid #000;
height: 100px;
}
<div class="cont">
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
</div>
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