I have the following html/css. Which renders like this:
.parent {
display: flex;
width: 200px;
height: 100px;
background-color: red;
}
.one {
flex: 1;
background-color: green;
}
.two {
flex: 1;
/* width: 100px; <-- this is what I'd like to achieve */
background-color: yellow;
}
.inner {
width: 150px; /* <-- this is bigger than width of .parent */
height: 50px;
background-color: blue;
}
<div class="parent">
<div class="one"></div>
<div class="two">
<div class="inner"></div>
</div>
</div>
As you can see the div
with .inner
is 150px
causing its parent div, with flex: 1, to take more space.
What I'd like to achieve is this:
I know the existence and tried to use, flex-grow
and flex-shrink
. I couldn't make it work.
The question: is there a way to make it work using only flexbox?