Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to line-break from css, without using <br />?

Tags:

html

css

output:

 hello How are you 

code:

<p>hello <br> How are you </p> 

How to achieve same output without <br>?

like image 350
Jitendra Vyas Avatar asked Apr 24 '10 07:04

Jitendra Vyas


People also ask

How do you automatically break lines in CSS?

word-wrap: break-word; is the current one. white-space: pre-wrap; is instead for something different! It preserves all whitespaces and linebreaks are ONLY done at \n (a linebreak in the source), <br> and as necessary to fill line boxes.

How do you insert a line break without HTML?

Try \n just after from where you want to break the line.

Do you need </ br?

In HTML, the <br> tag is used for line break. It is an empty tag i.e. no need to add an end tag. Writing <br> tag is perfectly fine.


2 Answers

You can use white-space: pre; to make elements act like <pre>, which preserves newlines. Example:

p {    white-space: pre;  }
<p>hello   How are you</p>

Note for IE that this only works in IE8+.

like image 81
Joey Adams Avatar answered Sep 23 '22 10:09

Joey Adams


Impossible with the same HTML structure, you must have something to distinguish between Hello and How are you.

I suggest using spans that you will then display as blocks (just like a <div> actually).

p span {    display: block;  }
<p><span>hello</span><span>How are you</span></p>
like image 28
Vincent Robert Avatar answered Sep 19 '22 10:09

Vincent Robert