Forcing a Line Break (Responsive)

What's the best way to force a line break (<br>) but based on screen size? Using JS, or hidden HTML tags?
17 Replies
Matt
MattOP2y ago
?
clevermissfox
clevermissfox2y ago
Hidden html tags is not it. Not sure what element you need to manipulate but flex-wrap or grid/media query?
Matt
MattOP2y ago
I'm trying to do it with an H2 tag The & in the title causes weird spacing issues which is why I'm trying to force a line break only at smaller screen sizes
clevermissfox
clevermissfox2y ago
I’m confused if you want the h2 to wrap onto multiple lines or want to adjust the spacing underneath the h2 … or both . Text-wrap: balance; and a max-width in a media query comes to mind
Matt
MattOP2y ago
Text-wrap: balance; is cool, never thought to use this before I just swapped around the heading text and it looks better. Client wanted specific wording which looked extremely weird once wrapped (was three lines, first two lines had weird line spacing because of certain letters) Thank you for your input though, greatly appreciated
ἔρως
ἔρως2y ago
strictly speaking, without thinking about what you're trying to achieve, sounds like you need the <wbr> tag
MarkBoots
MarkBoots2y ago
hard to tell without more info (or example) other option (maybe) would be
<h2>
<span>Hello</span>
<span>&</span>
<span>World</span>
</h2>
<h2>
<span>Hello</span>
<span>&</span>
<span>World</span>
</h2>
h2 {
display: flex;
flex-wrap: wrap;
column-gap: 0.25ch;

@media(width < 600px){
> span:first-of-type{ width: 100% }
}
}
h2 {
display: flex;
flex-wrap: wrap;
column-gap: 0.25ch;

@media(width < 600px){
> span:first-of-type{ width: 100% }
}
}
ἔρως
ἔρως2y ago
the <wbr> would be a better option, sometimes
Matt
MattOP2y ago
Interesting, thank you for this example From an SEO standpoint, are there any negatives with nesting tags within Headings?
ἔρως
ἔρως2y ago
no a <span> has no semantic meaning at all it's just text, basically
Matt
MattOP2y ago
Okay. I thought of nesting to fix but the quickest solution was to change the wording Basically, a custom font I used had weird top line spacing on certain characters
ἔρως
ἔρως2y ago
yeah, change the font
Matt
MattOP2y ago
and when adding line height, all other characters looked great besides two which were overlapping. Any more spacing and it would look odd, thats why I was trying to force a line break at certain screen sizing
ἔρως
ἔρως2y ago
well, which font is it?
Matt
MattOP2y ago
I changed it. It was a custom font I found on DaFont didn't have many variations for weights either
ἔρως
ἔρως2y ago
you did well in changing that sounds like a broken font

Did you find this page helpful?