在HTML中不需要P-end-tag(< / p>) [英] P-end-tag (</p>) is not needed in HTML

查看:103
本文介绍了在HTML中不需要P-end-tag(< / p>)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在XHTML中需要

< / p> ,但在HTML中不需要。有时候你必须关闭它,例如当你将段落对齐到左/右/中间。



混合使用< / p> 为在下面是一个坏主意?请注意,在第1段和第3段中没有结尾< / p> 标记。

< h1>我的文章< / h1>
< p>这是我的第一段。
< p class =align = right>这是我的第2段< / p>
< p>这是我的第3段。

为什么我不想关闭P标签:


  • 易于在我的CMS中工作(要求更高的代码以使其成为XHTML)
  • 1kb轻量级文件

解决方案


在XHTML中,不在HTML中。


正确


但有时你必须以任何方式关闭它,例如。当你将段落对齐到左/右/中间。

不正确。唯一需要显式结束标记的时间是当你想要结束段落并且紧接在段落内允许的内容之后(比如文本或内联元素)。这通常是一个糟糕的主意。


由于任何原因,混合使用P-end-tag p>

只有这种一致性是帮助代码维护的优点。


</p> is only required in XHTML but not in HTML. Some times you have to close it anyway , e.g. when you align the paragraph left/right/center.

Would mixing the usage of </p> as in the following be a bad idea? Note that there is no ending </p> tag in the 1st and 3rd paragraph.

<h1>My article</h1>
<p>This is my 1st paragraph.
<p class="align=right">This is my 2nd paragraph</p>
<p>This is my 3rd paragraph.

Reasons why I don't want to close the P-tags:

  • Easy to work with in my CMS (more demanding code to make it XHTML)
  • 1kb lighter files

解决方案

P-end-tag is only required in XHTML, not in HTML.

Correct

But some times you have to close it any way eg. when you align the paragraph left/right/center.

Incorrect. The only time you need an explicit end tag is when you want to end the paragraph and immediately follow it by something that is allowed inside a paragraph (such as text or an inline element). This is usually a bad idea.

Would it for any reason be a bad idea to mix the usage of P-end-tag

Only that consistency is a virtue which aids in code maintenance.

这篇关于在HTML中不需要P-end-tag(&lt; / p&gt;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆