I want the text div to be centered but the text to be aligned left.
The inner div (#introduction-child) is wider than its content. Instead it should be the width of the text (max-width 80vw).
The font-size seems to be changing the font size without changing its containers width.
Any idea how I can make it fit to content without using px/pt?
#introduction {
display: flex;
justify-content: center;
background-color: grey;
height: 100vh;
width: 100vw;
}
#introduction-child {
overflow-wrap: break-word;
max-width: 80vw;
background-color: #80b0ff;
margin-top: 28vh;
}
#introduction h2 {
font-size: 1.8em;
/* ??*/
}
<div id="introduction">
<div id="introduction-child">
<h2>Max Mustermann</h2>
<h2>Lorem ipsum dolor sit amet, consectetur ad</h2>
<h2>Lorem amet, consectetur ad</h2>
</div>
</div>
3
Answers
This is exactly what happens in your snippet. No problem.
No, your snippet shows that the the inner div is the same width as the text. No problem.
I do not understand what you mean, and the font-size does not appear to change.
give the min height and width to max to outer wrapper and then gave width as fit-content to the children with max height and width
this is my version of the answer and hope this works 🙂
to solve this problem please use align-item:center instead of justify-content: center;