Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use CSS to insert a line break after but not before an element?

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.

like image 365
Matt Avatar asked Sep 30 '13 17:09

Matt


2 Answers

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

.break:after {
    content:"\000A";
    white-space: pre;
}
like image 122
SLaks Avatar answered Sep 30 '22 22:09

SLaks


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.

like image 34
Jacques ジャック Avatar answered Sep 30 '22 22:09

Jacques ジャック