什么阻止我在HTML中使用任意标签? [英] What's stopping me from using arbitrary tags in HTML?

查看:92
本文介绍了什么阻止我在HTML中使用任意标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使是新的HTML5标签也不足以描述结构而不会退回到 div s。什么阻止我改变:

 < div class =post> 
< div class =userinfo>
< span class =name>凯西< / span>
< img class =avatarsrc =.../>
< / div>
< div class =body>
< p>等等等等等< / p>
< p>等等等等等< / p>
< p>等等等等等< / p>
< / div>
< / div>

类似于:

 <交> 
< userinfo>
<名称>凯西< /名称>
< img class =avatarsrc =.../>
< / userinfo>
< pbody>
< p>等等等等等< / p>
< p>等等等等等< / p>
< p>等等等等等< / p>
< / pbody>
< / post>

对我来说,第二个例子更简洁。有什么(即浏览器支持)阻止我这样做吗?

(我意识到它本质上就是XML,但在这种情况下,问题就变成了,浏览器支持什么样的呈现XML网页?)

解决方案

原因之一是Internet Explorer Firefox版本)没有对未定义的标签进行回退,并且对样式和嵌套都忽略它们。 如果没有shiv ,您的网站将在这些浏览器中爆发。


Even the new HTML5 tags aren't enough to describe structures without falling back to divs. What's stopping me from changing:

<div class="post">
    <div class="userinfo">
        <span class="name">Casey</span>
        <img class="avatar" src="..." />
    </div>
    <div class="body">
        <p>blah blah blah</p>
        <p>blah blah blah</p>
        <p>blah blah blah</p>
    </div>
</div>

into something like:

<post>
    <userinfo>
        <name>Casey</name>
        <img class="avatar" src="..." />
    </userinfo>
    <pbody>
        <p>blah blah blah</p>
        <p>blah blah blah</p>
        <p>blah blah blah</p>
    </pbody>
</post>

To me, the second example is a lot cleaner. Is there anything (i.e., browser support) stopping me from doing this?

(I realize what it is is, essentially, XML, but in that case, the question becomes, "what does browser support look like for rendering XML web pages?")

解决方案

One reason is that Internet Explorer (and earlier versions of Firefox) don't have a fallback for tags that are not defined and wind up ignoring them for both styling and nesting. Without a shiv, your site will break horribly in those browsers.

这篇关于什么阻止我在HTML中使用任意标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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