Sample:
#wrap {
outline: 1px solid fuchsia;
display: flex;
}
#left {
background: tan;
width: 100%;
}
#right {
background: teal;
width: 50px;
height: 50px;
}
<div id="wrap">
<div id="left"></div>
<div id="right"></div>
</div>
Screenshot:
Questions:
- When I use the browser element inspector, I see the right box is less than
50px
wide although it has a fixed width in the CSS. Why does it basically happen? - How can it be prevented?
Use
flex: 1 1;
on#left
instead ofwidth:100%
Source
You can also use flex-shrink: 0; on the #right element to prevent it from shrinking.
This just defines that the #right element should not be allowed to shrink e.g. stays at 50px.
For more informations about flex there are many good articles e.g. on css-tricks