简体   繁体   中英

How to indent HTML tag content

Maybe this is a too basic question.

<p>A long text here A long text here A long text here A long text here A long text here A long text here A long text here A long text here </p>

Is it possible to write something like:

<p>A long text here A long text here A long text here 
  A long text here ...
  ...
</p>

Also, help me tagging this question.

Well the paragraph tag removes leading white spaces and ignores enter breaks.

One way to achieve what you want would be to use the Preformatted tag <pre> which returns the result identical to it's base text (with spaces, breaks etc). Another way would be to try styling it with CSS (width, text-indent, etc) in the way it's best representative to the user.

All of the other answers include some truth, here is a different approach using CSS:
http://jsfiddle.net/Volker_E/p3pgz/

Simply include:

p {
   white-space: pre;
}

This ensures output of white space and line breaks as written in HTML editor. White-Space property description at MDN .

您可以简单地使用

<br/> tag within the <p> tag for getting the required indentation.. something like <p>A long text here A long text here A long text here <br/> A long text here A long text here A long text here </p>

You can either use &nbsp; a few times, or use CSS:

p {
    text-indent:-20px;
    padding-left:20px;
}

Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM