How can I make the <h1>
elements take on the next line if the width of the parent element becomes too small?
EXAMPLE:
Each word here is an <h1>
element. They are spaced by their parent <div>
using display: flex;
and gap: 1rem;
.
Now, the width of the parent <div>
is reduced, so how can I make the other <h1>
elements occupy the next line like the image below?
CODE:
<div className="flex gap-4">
{
text.split(" ").map((e, i) => (
<h1 key={i} className="text-color-1 text-3xl font-bold text-center lg:text-left md:text-5xl lg:text-7xl whitespace-pre-line inline">
{e}
</h1>
))
}
</div>
2
Answers
Consider applying
flex-wrap: wrap
to the<div>
element via theflex-wrap
Tailwind utility class:I would just remove the
whitespace-pre-line inline
classes.