html - 在代码标签中显示新行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32550310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 18:13:36  来源:igfitidea点击:

html - Display new line in code tag

html

提问by Ricardo

I'm trying to display code but everything is showed in one line. How can I display multiline code tag?

我正在尝试显示代码,但所有内容都显示在一行中。如何显示多行代码标签?

This is my code:

这是我的代码:

index.html

索引.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<title>Documentación: Events</title>
<body>
<code>
    {
    "id_tabla":3,
    "fecha":"02-09-2015",
    "privacidad":0,
    "timediff_m": "00"
    }
</code>
</body>

And this is how is showed in browser:

这是在浏览器中的显示方式:

{"id_tabla":3,"fecha":"02-09-2015","privacidad":0,"timediff_m": "00"}

Edit

编辑

I can only use <code>tag

我只能使用<code>标签

采纳答案by Avalanche

This has already been answered here:

这已经在这里得到了回答:

code {
  display: block;
  white-space: pre-wrap   
}
<code>
    {
    "id_tabla":3,
    "fecha":"02-09-2015",
    "privacidad":0,
    "timediff_m": "00"
    }
</code>

回答by Lipis

Use <pre>instead of <code>.

使用<pre>代替<code>

<pre>
  {
    "id_tabla": 3,
    "fecha": "02-09-2015",
    "privacidad": 0,
    "timediff_m": "00"
  }
</pre>

You should use <code>if you want to have something inline and <pre>when you need something multiline.

<code>如果您想要内联内容以及<pre>需要多行内容,您应该使用。