html约定-自闭标签,>或/> ;,以其他方式< br>或< br />
从网上学习一些教程时,我看到很多人把标签打开,例如< link ..>
,< img .. >
。但是,当我使用Netbeans编辑它们(HTML / JSP页面)时,在这些标记上显示红色背景,直到我在其中添加斜线为止。 < br>
-> < br />
。
When take some tutorial from web, I see many people leaves tags open like <link ..>
, <img ..>
. But when I use Netbeans to edit them (the HTML/JSP pages), it show a red background on those tags until I add the slash into them. <br>
--> <br/>
.
哪种方法是编写基于HTML的代码的正确方法?
Which is the correct way to write HTML-based code?
两者都适合HTML。
Both are fine for HTML. Though not for XHTML which is an XML dialect.
某些元素不需要结束符( />
),尽管不是XML的XHTML。标签-特别是空元素(不包含内容的元素)。例如< hr>
和< br>
。这些可以也是自闭的(< hr />
和< br />
)。这种自我关闭等同于在open标签之后紧接一个close标签。
Some elements do not need a closing (/>
) tag - in particular empty elements (those that do not have content). Examples are <hr>
and <br>
. These can also be self closing (<hr />
and <br />
, respectively). This self closing is equivalent to having a close tag immediately after the open tag.
对于XML,此类非关闭标签无效-必须关闭,无论是self结束或具有结束标签。因此< hr>
不是有效的XML,但是< hr />
和 < hr>< / hr>
是。
For XML, such a non closing tag is not valid - it must be closed, either self closing or have a closing tag. So <hr>
is not valid XML, but <hr />
and <hr></hr>
are.
HTML不是XML,但是为了更好的兼容性,某些工具尝试发出尽可能多的XML像HTML一样。
HTML is not XML, but for better compatibility some tools try to emit as much XML like HTML as possible.