为什么某些HTML标签以正斜杠结尾? [英] Why do some HTML tags end with a forward slash?

查看:189
本文介绍了为什么某些HTML标签以正斜杠结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个菜鸟问题,但是我需要知道我需要知道的内容:)

This is probably a rookie question, but I need to know what I need to know :)

为什么某些HTML标签以正斜杠结尾?

Why do some HTML tags end with a forward slash?

例如:

 <meta name="keywords" content="bla bla bla" />

最后一个斜杠代表什么?如果我将其删除会怎样?

What's that last forward slash for? What happens if I remove it?

还有其他一些标签也有这个...我已经删除了一些没有任何反应的

Also some other tags have this as well... I have removed some without anything happening.

推荐答案

XHTML 中,<foo /><foo></foo>的简写.在HTML中,语法为晦涩,并标记为不要" ,因为浏览器不支持.

In XHTML <foo /> is shorthand for <foo></foo>. In HTML the syntax is obscure and marked as "don't do this" as browsers don't support it.

如果您正在编写XHTML,但假设它是HTML (这样,不支持XHTML的浏览器(例如Internet Explorer 8)就可以处理它),那么规范中定义为EMPTY的元素必须以这种方式表示(而那些不是必须如此).

If you are writing XHTML but pretending it is HTML (so that browsers (such as Internet Explorer 8) which don't support XHTML can handle it), then elements defined as EMPTY in the specification must be represented that way (and elements which are not must not).

在撰写此答案和 查看全文

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