I have a rather long text inside an intrinsically sized div
. For visual reasons I’d like the div
to break at a given point but only when no "natural" line break would occur "before" this point:
I could achieve this by adding a <br>
, placing the text into multiple div
s etc. but I found no way to ignore this break, when the div
shrinks below the point where it would naturally break "before" that preferred break point:
Is there any technique to achieve this with pure CSS & HTML?
Example code
Here’s an example with the "static" line break via <br>
which shows the line break at the correct position when the div
is very wide but does not work as required when the div shrinks (second screenshot above):
<div class="parent">
<div class="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse non orci
in nunc venenatis luctus et eget mauris.
<br>
Pellentesque nec ante dignissim, malesuada tortor ac, rhoncus ante.
</div>
</div>
.parent {
display: flex;
font-family: Inter;
font-size: 18px;
}
.content {
background: yellow;
padding: 8px;
}
Additional note
I’m specifically looking for a solution which does not require any fixed sizing like max-width
div, media queries etc. b/c they would all be bound to the used font, font-size, browser zoom level etc. and could break e.g. when the user overrides the font(size) in his browser settings etc.
2
Answers
You could use a regular
<br>
tag and hide it, when the viewport size gets smaller.Maybe you have to try out for yourself which breakpoint fits best.
Something like this?