0

I have text that I'd like to display on two lines. Adding a <br> tag accomplishes that:

<!-- Browser displays two lines of text, as intended -->
<a>Text unit 1<br>
   Text unit 2 </a>

I would like to apply styling to 'Text unit 2'. No matter what tag I apply to the text, the browser ignores the <br> as soon as I introduce it:

<!-- Browser displays one line of text, not as intended -->
<a>Text unit 1<br>
   <literally any HTML tag>Text unit 2</tag></a>

I've tried <span>, <p>, <div>, <em>, and <strong> tags. All of them display as a single line instead of two lines as soon as the tags are introduced.

How do I force the <br> tag to implement a line break?

Edit: Firefox 85 and Chromium 87.0

Darien Marks
  • 446
  • 4
  • 18

1 Answers1

1

If the <a> itself is display: flex then the <br> element itself becomes a flex element and will be laid out according to flex rules. You'd end up with a flex layout that looks like this: | text 1 | <br /> | text 2 | with everything laid out in a row:

a {
  display: flex;
}
<a>Text unit 1<br><div>Text unit 2</div></a>

You could clean this up by making each child an element and setting flex-direction to column:

a {
  display: flex;
  flex-direction: column;
}
<a>
  <div>Text unit 1</div>
  <div>Text unit 2</div>
</a>

But if that's all you're doing you don't need flex at all:

<a>
  <div>Text unit 1</div>
  <div>Text unit 2</div>
</a>
ray
  • 26,557
  • 5
  • 28
  • 27