简体   繁体   English

如何缩进HTML代码示例

[英]How to indent html code examples

I have a website or a html page and I want to indent my code for my visitors to see. 我有一个网站或一个html页面,我希望缩进代码以供访问者查看。 For example: 例如:

<html>
<head>
</head>
<body>
<pre>
&lt;html>
&lt;body>
&lt;p>
hi
&lt;/p>
&lt;/body>
</pre>
</body>
</html>

In html, is there a way to indent a block code without using a lot of &nbsp ; 在html中,有一种无需使用大量&nbsp即可缩进块代码的方法。 , like the <blockquote> tag. ,如<blockquote>标记。 this way, I can use something like this: 这样,我可以使用这样的东西:

<html> <HTML>
<head> &lt/head> <body> <head>&lt / head> <body>
<p> Hi <p>嗨
</p> </ p>
</body> </ BODY>
</html> Using: </ html>使用:

 <blockquote> &lt;html> <blockquote> &lt;head> &lt/head> &lt;body> <blockquote> &lt;p> <blockquote> Hi </blockquote> &lt;/p> </blockquote> &lt;/body> </blockquote> &lt;/html> 

I was wondering if there was a better way to indent blocks of code. 我想知道是否有更好的方法来缩进代码块。 If not, I was wondering if there was a way to use css to change it so there is no line on the side and it looks just link a normal indent to the user. 如果没有,我想知道是否有一种方法可以使用css对其进行更改,以使侧面没有行,并且看起来只是将普通缩进链接到用户。

You may do it with CSS. 您可以使用CSS来实现。 The text-indent property specifies the indentation of the first line in a text-block. text-indent属性指定文本块中第一行的缩进。 Try; 尝试;

blockquote  {
    text-indent: 50px;//define indent in pixels
}

Here is a demo http://www.w3schools.com/cssref/tryit.asp?filename=trycss_text-indent 这是一个演示http://www.w3schools.com/cssref/tryit.asp?filename=trycss_text-indent

You can use the pre tags to make preformatted text which can be indented via normal spaces/tabs. 您可以使用pre标签来制作可以通过常规空格/制表符缩进的预格式化文本。

<pre>
    &lt;html>
        &lt;head>&lt;/head>&lt;body>
            &lt;p>
                Hi
            &lt;/p>
        &lt;/body>
    &lt;/html>
</pre>

JSFiddle 的jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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