14

For example:

HTML:

The quick brown fox <span class="break">{BREAK}</span> jumps over the lazy dog.

I want this to display:

The quick brown fox {BREAK}

jumps over the lazy dog.

I looked into the display property, but display:inline; doesn't break anywhere and display:block puts breaks on both sides.

I also looked into the :after pseudo-class, but .break:after{content:"\000A";} ends up rendering as a space, rather than a line feed.

Matt
  • 21,026
  • 18
  • 63
  • 115

2 Answers2

31

By default, HTML elements ignore whitespace.
You need to change that:

.break:after {
    content:"\000A";
    white-space: pre;
}
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
3

http://jsfiddle.net/bMKrc/1/

html:

The quick brown fox <span class="break"></span> jumps over the lazy dog.

CSS:

.break{
    display:block;
}

And that's all you need. display:block may cause it to break on both sides, but it does not cause there to be an extra line. View my fiddle.

Jacques ジャック
  • 3,682
  • 2
  • 20
  • 43
  • @Matt Just because the OP says something does not mean it's true. You achieve the desired result with display block. Check out my fiddle if you don't believe me. – Jacques ジャック Sep 30 '13 at 20:09
  • In case it was confusing "{BREAK}" is still supposed to be part of the text. – Matt Sep 30 '13 at 20:41
  • 1
    Oh, that does not make much sense, but it's not my project. I thought he was showing where to put the break. But that does not warrant your being rude. – Jacques ジャック Sep 30 '13 at 20:53
  • Ok, I appologize if I came off as rude. The reason it does not make much sense is because I only gave an illustrative example of my problem and not my actual problem. – Matt Sep 30 '13 at 21:11
  • The jsfiddle.net makes it very clear. I tried many many ways to put a line break between an img and an Angular {{ }} binding that are both inside a button, and this is the only thing that works. And its so self explanatory in the code, especially if you call the class lineBreak. – Mike_Laird Dec 24 '14 at 18:46
  • 1
    ..soo, why don't use
    then?
    – Max Yari Aug 31 '15 at 16:07