您需要在HTML中关闭元标记和链接标记吗?(Do you need to close meta and link tags in HTML?)
我只是在阅读某人的HTML,从未在HTML头部分中关闭元标记和链接标签。 代码工作正常 正在关闭这些标签可选?
我认为如果一个标签没有被关闭,就会发生错误。
I was just reading somebody's HTML who never closed meta and link tags in the HTML head section. The code worked fine; is closing these tags optional?
I thought it would be malformed if a tag was not closed.
最满意答案
标签必须始终被标签关闭符号
>
(如果我们忽略某些SGML规则,名义上应用于非XHTML HTML但从未在浏览器中实现)。你的意思是要求这些元素是否需要由结束标签来关闭。 答案是非XHTML HTML(包括HTML序列化中的HTML5),
meta
标签和link
元素不需要或允许使用结尾标签。 然而,实际上,如果您使用浏览器,那么浏览器只会忽略它们的显式结束标记,以及货物崇拜/
之前的。 而且,即使正式允许/
在HTML序列化中,HTML5也使得这种允许性成为规则。在XHTML中,XML规则适用,所以每个元素无一例外都必须同时具有起始标记和结束标签,但是如果元素内容为空,则可以为两个角色使用相同的标签,例如
<meta name="foo" content="bar"/>
作为<meta name="foo" content="bar"></meta>
缩写。 如果在向符合规定的浏览器提供XML(XHTML)内容类型的文档时违反了这一点,那么您的文档根本不会显示; 将显示一条错误消息。当使用具有HTML内容类型(
Content-Type: text/html
)的XHTML服务器时,由于XHTML文档几乎总是在网络上,所以浏览器实际上将应用非XHTML HTML规则。总结:
- 通常,只使用
<meta ...>
与no/
- 如果您真正在XHTML解析实际应用的上下文中使用XHTML,则可以通过XML规则进行播放(并确保您了解它们)
- 如果你的老板告诉你写
<meta ... />
,那么 它没有用,但它不会造成伤害(除非您尝试验证例如agaist HTML 4.01 doctype)。A tag must always be closed by the tag close symbol
>
(if we ignore certain SGML rules that nominally apply in non-XHTML HTML but were never implemented in browsers).What you mean to ask is whether the elements need to be closed by end tags. The answer is that non-XHTML HTML (including HTML5 in HTML serialization), no end tag is required or allowed for
meta
andlink
elements. In practice, however, browsers just ignore explicit end tags for them, as well as the cargo-cult/
before>
, if you use them. And HTML5 makes this permissiveness a rule by even formally allowing the/
in HTML serialization, too.In XHTML, XML rules apply, so every element, without exception, must have both a start tag and an end tag, but the same tag may be used for both roles if the element content is empty, e.g.
<meta name="foo" content="bar"/>
as short for<meta name="foo" content="bar"></meta>
. If you violate this when serving a document with an XML (XHTML) content type to a conforming browser, then your document is not displayed at all; an error message is shown instead.When using XHTML server with HTML content type (
Content-Type: text/html
), as XHTML documents almost always are on the web, then browsers will actually apply the non-XHTML HTML rules.To summarize:
- normally, use just
<meta ...>
with no/
- if you are really using XHTML in a context where XHTML parsing is actually applied, play by XML rules (and make sure you know them)
- if your boss tells you to write
<meta ... />
, do so; it’s not useful, but it causes no harm (except if you try to validate e.g. agaist HTML 4.01 doctype).
相关问答
更多-
您需要创建一个EventHandler来检查元数据并使它们对Sharepoint有意义。 创建并安装后,每次将文件上传到文档库时,代码都会控制并处理元数据。 You'll need to create an EventHandler to check that metadata and make them meaningful for Sharepoint. After create and install it, everytime you upload a file to your document l ...
-
您将Schema Microdata元标记放在html文件中吗?(Do you put Schema Microdata meta tags in the html body?)[2022-03-03]
如果是meta元素 有一个itemprop属性和一个content属性,和 没有name属性,没有http-equiv属性,没有charset属性, 那么在body有这个meta是有效的。 (如果值是URL,则必须使用link 。) 为什么? 因为Microdata规范改变了HTML5 。 (请注意, RDFa还可以通过在某些情况下允许body中的meta来更改HTML5 。) 如果您要保留meta标记在 ,那么您将如何将这两个日期与他们的评论相关联? 您可以使用itemref属性 :标签必须始终被标签关闭符号> (如果我们忽略某些SGML规则,名义上应用于非XHTML HTML但从未在浏览器中实现)。 你的意思是要求这些元素是否需要由结束标签来关闭。 答案是非XHTML HTML(包括HTML序列化中的HTML5), meta标签和link元素不需要或允许使用结尾标签。 然而,实际上,如果您使用浏览器,那么浏览器只会忽略它们的显式结束标记,以及货物崇拜/之前的。 而且,即使正式允许/在HTML序列化中,HTML5也使得这种允许性成为规则。 在XHTML中,XML规则适用,所以每个元素无 ...simplexml android无法使用非关闭元标记解析html(simplexml android Can't parse html with non-closing meta tag)[2022-09-12]
您可以在将文件传递给解析器之前从文档中删除元标记甚至头标记。 如果它存储在字符串中使用此 you can remove the meta tag or even the head tag from the document before passing it to the parser. If it is stored in a string use this各种元标记的含义(Meaning of various meta tags)[2022-11-28]
用于使浏览器在30秒后刷新页面 修改后的元标记会记录上次更新网站的时间 用于定义HTML文档的字符集尝试这样的事情: var gutterWidth = {masonry:gutterWidth}; $tumblelog.imagesLoaded(function () { $tumblelog.masonry({ columnWidth: 500, // DEFINES POST WIDTH IN PX gutterWidth: gutterWi ...那些标签仅供Facebook抓取工具使用。 Safari等移动浏览器完全忽略它们。 你需要使用这样的JavaScript: setTimeout(function() { window.location = "https://itunes.apple.com/path/to/your/app/"; }, 25); // If "yourapp://" is registered, your app will launch immediately and the // timer won't ...是的,pandoc将执行此操作,但仅限于使用版本1.12.3或更高版本。 pandoc -f html -t markdown -s input.html -o output.md Yes, pandoc will do this, but only if you use version 1.12.3 or later. pandoc -f html -t markdown -s input.html -o output.mdHTML元标记足够了吗?(Are HTML meta tags enough?)[2023-02-12]
在您的页面中,您有许多空元素:您可以从GWT创建Meta标签: MetaElement element = Document.get().createMetaElement(); element.setName("name"); element.setContent("content"); 并将其添加到头部: NodeListnode = Document.get().getElementsByTagName("head"); Element element2 = (Element) node.getItem(0) ... 相关文章
更多- HTML meta标签
- HTML 排版标记
- HTML 字体标记
- 删除Hbase的META中多余表项
- 关于微信公众号内嵌网页的几个meta标签
- jquery 怎么得到link中text的属性
- 高薪诚聘搜索引擎架构师-Close
- 在html使用CSS的方式
- transaction.auto_close_session参数的问题
- HTML5 标签语法变化和使用概念
最新问答
更多- 在javascript中创建类以创建对象并在Java中创建类和对象之间的区别(Difference between creating a class in javascript to create an object and creating an class and object in Java)
- Facebook API:将身份验证详细信息从Javascript SDK发送到PHP SDK(Facebook API: Send authentication detail from Javascript SDK to PHP SDK)
- 如何停止队列动画jquery?(How can I stop queue animation jquery?)
- 使用C#的井字游戏中的人工智能(Artificial Intelligence in Tic-Tac-Toe using C#)
- 多少流量可以共享虚拟主机(对于Python Django站点)支持?(How Much Traffic Can Shared Web Hosting (for a Python Django site) support?)
- 带有CIFilters的CAShapeLayer(CAShapeLayer with CIFilters)
- 如何在Angular 2中读取JSON #text(How to read in Angular 2 the JSON #text)
- 如何在xml中读取自闭标签的属性?(How to read self closing tag's attribute in xml?)
- 无法使用http put将图像上传到亚马逊S3(Cannot upload image to amazon s3 using http put)
- 文件结束无限循环(end of file infinite while-loop)
- 在cpp的模板(template in cpp)
- 在构建库时,clang和clang ++有什么区别?(What's the difference between clang and clang++ when building a library?)
- ng类中的表达式(expression inside ng-class)
- 在PHP中获取随机布尔值true / false(Get random boolean true/false in PHP)
- 管道的高效分块用于严格的字节串(Efficient chunking of conduit for strict bytestring)
- Python ternary_operator(如果其他标志做了其他操作,则执行其他操作)(Python ternary_operator (do-somthing if flag else do-another))
- Sencha Touch面具发布(Sencha Touch mask ondisclosure)
- 验证脚本上的通知[重复](Notices on validation script [duplicate])
- 朋友功能(friend function)
- 基于角坐标平移和变换平面几何(Translate and transform plane geometry based on corner coordinates)
- Rails:'如果在本地运行'条件javascript标记包括(Rails: 'if running locally' conditional javascript tag include)
- 解压文件(Unzipping files)
- 使用ui-router以角度加载变量状态(loading in variable states with ui-router in angular)
- 创建Azure云服务需要多长时间?(how long does it take to create an Azure Cloud Service? How to view log information?)
- 指向整数的指针数组(Array of pointers to integers)
- Laravel服务提供商没有看到我的包的主要类(Laravel service provider does not see the main class of my package)
- 这个关于VSS / RSS / PSS / USS的解释是否准确?(Is this explanation about VSS/RSS/PSS/USS accurate?)
- 在Django-Admin中通过row-id排序显示项目(Ordering the display items by row-id in Django-Admin)
- 如何使用cythonize启用`--embed`?(How to enable `--embed` with cythonize?)
- 用于将文本多行设置的Excel脚本(Excel script for ereasing text multiple rows)