html约定-自闭标签,>或/&gt ;,以其他方式< br>或< br /> [英] html convention - self-close tag, > or />, in other way <br> or <br/>

查看:99
本文介绍了html约定-自闭标签,>或/&gt ;,以其他方式< 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.

这篇关于html约定-自闭标签,&gt;或/&gt ;,以其他方式&lt; br&gt;或&lt; br /&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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