简体   繁体   English

如何缩进<code>elements? Example in details</code> <code>elements? Example in details</code>

[英]How do I indent <code> elements? Example in details

http://htmlpocketreference.110mb.com/taggroups.html http://htmlpocketreference.11​​0mb.com/taggroups.html

For the site above, how would I indent all the code. 对于上面的网站,我将如何缩进所有代码。 I don't want it aligned with the paragraph and headings. 我不希望它与段落和标题保持一致。 I want it to be one indent level in. You can check my source if you want and the css is embedded in the html already. 我希望它成为一个缩进级别。如果需要,可以检查我的源代码,并且CSS已嵌入html中。

Also, any suggestions on how to improve it? 另外,关于如何改进它的任何建议?

(Note: I'm not publishing the site, I'm just practicing on getting all the formatting right. (注意:我不是在发布网站,而是在尝试正确设置所有格式。

To indent each <code> block, you can use something like: 要缩进每个<code>块,可以使用类似以下内容的<code>

code{
     display: block;
     margin: 0 40px;
}

To indent only the first line of each <code> block, 要仅缩进每个<code>块的第一行,

code{
     text-indent: 40px;
}

40px is just a suggestion; 40px只是一个建议; you can adjust the indentation width to suit your visual needs. 您可以调整压痕宽度以适合您的视觉需求。

Did you try something like this? 你尝试过这样的事情吗?

code {
position: relative;
left: 20px;
}

The previous two answers got the methods spot-on: 前面的两个答案使方法变得一目了然:

code
{
  display: block;
  margin-left: 40px;
  font-family: monospace; /* I would add this too, as it makes the code more readable. */
}

Also, as you are displaying code (I hope), try SHJS . 另外,在显示代码时(希望如此),请尝试使用SHJS Good luck! 祝好运!

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

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