为什么有些元标签末尾有“/”,而有些没有?

为什么有些元标签末尾有“/”,而有些没有?

如果我们看一下大名单在今天的任何文章中都应该有的社交元标签中,我们可以看到其中一些在右括号前有“/”,而有些则没有。

<!-- Update your html tag to include the itemscope and itemtype attributes. -->
<html itemscope itemtype="http://schema.org/Article">

<!-- Place this data between the <head> tags of your website -->
<title>Page Title. Maximum length 60-70 characters</title>
<meta name="description" content="Page description. No longer than 155 characters." />

<!-- Schema.org markup for Google+ -->
<meta itemprop="name" content="The Name or Title Here">
<meta itemprop="description" content="This is the page description">
<meta itemprop="image" content="http://www.example.com/image.jpg">

<!-- Twitter Card data -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@publisher_handle">
<meta name="twitter:title" content="Page Title">
<meta name="twitter:description" content="Page description less than 200 characters">
<meta name="twitter:creator" content="@author_handle">
<!-- Twitter summary card with large image must be at least 280x150px -->
<meta name="twitter:image:src" content="http://www.example.com/image.html">

<!-- Open Graph data -->
<meta property="og:title" content="Title Here" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://www.example.com/" />
<meta property="og:image" content="http://example.com/image.jpg" />
<meta property="og:description" content="Description Here" />
<meta property="og:site_name" content="Site Name, i.e. Moz" />
<meta property="article:published_time" content="2013-09-17T05:59:00+01:00" />
<meta property="article:modified_time" content="2013-09-16T19:08:47+01:00" />
<meta property="article:section" content="Article Section" />
<meta property="article:tag" content="Article Tag" />
<meta property="fb:admins" content="Facebook numberic ID" />

我想知道是否有任何其背后有什么特殊原因吗?或者仅仅是撰写此列表的文章作者的不一致?

答案1

这是不一致的。

HTML 规则不要求标签末尾需要有 /。

XML 规则规定,如果标签没有对应的结束标签,则需要使用 /。

XHTML 的规则基本上是 XML 和 HTML 的结合(因此 XHTML 中需要斜线)。一些使用 HTML 的人试图遵循许多规则,因此他们最终会遵循 XML 规则,即使不需要遵守 XML 规则。

但是,这些额外的斜线实际上并没有造成太大影响。(它们只是占用了一点点带宽和相关的处理能力。流量微不足道的网站不太可能注意到这一点。)因此,网站管理员可以逃避不一致的问题,而他们似乎确实在这么做。他们可能使用了包含斜线的某些软件,然后复制并粘贴了这些标签,而其他标签则由其他软件创建。(或者,也许所有这些代码都是由同一软件创建的,但使用了不同的选项,也许是在不同的时间。)

相关内容