.row {
display: flex;
align-items: center; /* Centers items vertically */
background-color: yellow;
height: 100vh;
}
.column {
max-width: 400px;
background-color: red;
flex-grow: 1;
}
<div class="row">
<div class="column">Text</div>
</div>
Inside a flex box element I have a div with a max-width. Inside the div will be headings. Some headings are long, some short. Even with short headings I want the div to expand to the max-width (not shrink to the width of the child element). Is this possible without using breakpoints?
I’ve tried various combinations of max-width combined with width and min-width, but can’t get it to work
.row {
display: flex;
align-items: center
}
.column {
max-width: 90rem;
background-colour: red;
}
<div class="row">
<div class="wrapper">
<div class="column">Text</div>
</div>
</div>
2
Answers
You have to maintain the hierarchy while targeting the child element.
Also,
flex-grow: 1
will result in same output.It’s because you use
Flex-grow:1;,by using flex-grow only, its basis tends to be auto, for a flex item that has auto as its basis, it normally takes the width of the content in it. So advisely you use
Flex-flow:1; then your max-width