I have a chunk of text. My headlines should go wider than the paragraph text. To make that possible I use max-width. The first problem is that my single word paragraph is centered. I fix it by using width but as soon as I do that max-width no longer applies. Why is that? How can I fix it?
- You can be creative, but JS solutions is a no go for me here.
- I know I can wrap elements to style them individually but I don't want to be required to add extra markup in the html.
- At a later point I may have images etc that also don't follow the paragraph width. Therefore a long term less hacky solution is better.
Example
You need to try it on a mobile. The paragraph then refuses to scale down but keeps itself to 640px.
.text {
width: 840px;
background: #eee;
display: flex;
flex-direction: column;
align-items: center;
}
h1 {
max-width: 640px;
text-align: center;
}
p {
max-width: 400px;
width: 400px;
/* To prevent the one word to be centered */
}
<div class="text">
<h1>
A really very long headline indeed, to tell a story
</h1>
<p>
Soufflé sesame snaps tart chocolate chupa chups candy canes jujubes. Sweet brownie cheesecake tootsie roll donut bear claw macaroon brownie jelly. Cake toffee lollipop lollipop fruitcake caramels carrot cake gingerbread chocolate. Cotton candy powder
tiramisu liquorice brownie lemon drops pastry.
</p>
<p>
One word.
</p>
</div>