简体   繁体   English

跳过html结束标记

[英]Skipping html closing tags

Google chrome (and probably all the recent browsers) automatically adds the closing tag of html elements when they are missing. 当chrome元素丢失时,Google chrome(可能还包括所有最近的浏览器)会自动添加html元素的结束标记。 It will automatically add the closing tag at the end of the element parent . 它将自动在元素parent的末尾添加结束标记

Example 1: 范例1:

<tag1>content1<tag2>content2<tag3>content3

Will output: 将输出:

<tag1> 
    content1 
    <tag2> 
        content2
        <tag3> 
            content3 
        </tag3>
    </tag2> 
</tag1>

Example 2: 范例2:

<tag1>content1<tag2>content2</tag2><tag3>content3

Will output: 将输出:

<tag1> 
    content1 
    <tag2> 
        content2
    </tag2>
    <tag3> 
        content3 
    </tag3>
</tag1>

I know that the previous html examples are invalid and difficult to read . 我知道前面的html示例无效且难以阅读 But removing closing html tags following this rule with an html minifier could reduce the templates's size. 但是,遵循此规则并使用html缩小符删除关闭的html标签可以减小模板的大小。 Why aren't html minifier using this rule ? 为什么html minifier不使用此规则? Is there some restrictions ? 有一些限制吗?

Edit: Context: I am not talking about any name tag in particular, that's why i used tagX in my examples. 编辑: 上下文:我并不是特别在谈论任何名称标签,这就是为什么我在示例中使用tagX的原因。 Eg. 例如。 with angularjs element directives 与angularjs元素指令

Good observation. 好观察。 This has been done by Firefox for a long time as well as it helps developers with semantics. Firefox已经做了很长时间了,它可以帮助开发人员理解语义。 But the issue we run into is what we just mentioned. 但是,我们遇到的问题就是我们刚才提到的问题。 Firefox, Chrome. Firefox,Chrome。 But what does IE do? 但是IE会做什么? Or screenreaders? 还是屏幕阅读器? I know Safari is not doing this at the same level FF and Chrome are. 我知道Safari不会在FF和Chrome处于同一级别上执行此操作。

It comes down to browser support and having a general global consensus on valid html. 归结于浏览器支持以及对有效html的总体共识。 Having a blueprint to work with instead of browser specific implementations means we can run web technology more safely across old and new devices who are not fail safe-ing their parsers. 使用蓝图而不是使用特定于浏览器的实现方式意味着我们可以在安全解析器不会失败的新旧设备之间更安全地运行网络技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM