Even the new HTML5 tags aren't enough to describe structures without falling back to div
s. What's stopping me from changing:
即使是新的HTML5标签也不足以描述结构而不回到divs。是什么阻止我改变:
<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?")
(我知道它本质上是XML,但在这种情况下,问题变成了“浏览器对呈现XML web页面的支持是什么样子的?”)
6 个解决方案
#1
6
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.
原因之一是Internet Explorer(以及早期版本的Firefox)没有为未定义的标记提供退路,最终在样式和嵌套上都忽略它们。如果没有shiv,你的站点会在这些浏览器中崩溃。
#2
3
You can use your own tags, but the problem is that since they're not standard, browsers won't know that they may have matching closing tags. And of course, the document won't validate as proper HTML/X-HTML.
您可以使用自己的标记,但问题是,由于它们不是标准的,浏览器不会知道它们可能有匹配的结束标记。当然,文档不会作为适当的HTML/X-HTML进行验证。
<blah>
This is some <span>test</span> test text with another <bogus>tag</bogus> tag
within, which ends with a fake self-closing <tag />
</blah>
Browsers will see <blah>
, not now how to deal with it, and treat it as essentially "nothing" and ignore it. Then they'll happily parse away on to the next bit, and see some plain text, with a valid span inside. Eventually they'll reach the </blah>
and ignore that as well.
浏览器将看到
This is why Javascript and CSS had to support the opening HTML comment sequence as part of their respective language definitions:
这就是为什么Javascript和CSS必须支持开放的HTML注释序列作为它们各自语言定义的一部分:
<script type="text/javascript">
<!-- // <--actually a part of the javascript spec, treated as a comment.
alert('hey!');
//-->
</script>
When Javascript was first introduced, there were still MANY other browsers out there that were entirely unaware of Javascript, and so they'd ignore tags, and happily output your Javascript code. Ditto for CSS.
当Javascript刚开始引入时,仍然有很多浏览器完全不知道Javascript,所以它们会忽略标记,并愉快地输出Javascript代码。同上的CSS。
If you really need custom tags, you can produce the document as XML with your own DTD attached, and use XSLT to transform it into a valid HTML/X-HTML document.
如果您确实需要自定义标记,可以使用自己的DTD将文档作为XML生成,并使用XSLT将其转换为有效的HTML/X-HTML文档。
#3
1
The issue is that it would not validate and the new tags would simply be ignored.
问题是,它不会验证,新的标记将被忽略。
#4
1
Most browsers will just treat the tags as arbitrary (like how old browsers treat HTML5 tags). Nothing is stopping you from using your own tags, but it's not a well-accepted way to code HTML. HTML is supposed to use pre-defined tags.
大多数浏览器只会将标签视为任意的(就像旧的浏览器对待HTML5标签的方式一样)。没有什么能阻止您使用自己的标记,但这不是一种广为接受的编写HTML的方式。HTML应该使用预定义的标签。
If you're interested in coding with arbitrary tags, you could just go with XML. You can format XML with XSLT (used in a way similar to stylesheets, but much more powerful). Have a look here: http://www.w3schools.com/xml/xml_xsl.asp
如果您对使用任意标记进行编码感兴趣,可以使用XML。您可以使用XSLT来格式化XML(使用方式类似于样式表,但功能要强大得多)。看看这里:http://www.w3schools.com/xml/xml_xsl.asp
#5
1
What is the goal of the tags you chose? If your goal is to present information, then using divs and other presentation-oriented structures is great. Your tags look more like they are attempting to describe the actual data. If that is the case, then XML with XSLT transforms on the server side to output HTML for presentation markup is best. Remember that a browser is simply a rendering engine and it uses the HTML spec as it's blueprint of what to render for a given site. The browser doesn't need to understand the information like a "post" or "userInfo" because it has no context for undertsanding what to do from a rendering perspective with that information. CSS can help a browser understand what you want to do visually but ask yourself first whats the goal of having your markup that way, to store your data (XML-style) or to present it. If to present it, then you should go with the standards if you want to continue to use a browser as your rendering engine. Good luck, would be great if we could all define our presentation schemes though, fun idea!
您选择的标签的目标是什么?如果你的目标是呈现信息,那么使用divs和其他面向呈现的结构是很好的。您的标记看起来更像是试图描述实际数据。如果是这样,那么在服务器端使用XSLT转换的XML输出HTML作为表示标记是最好的。请记住,浏览器只是一个呈现引擎,它使用HTML规范作为给定站点呈现内容的蓝图。浏览器不需要像“post”或“userInfo”这样理解信息,因为它没有上下文来理解从呈现透视图中使用这些信息做什么。CSS可以帮助浏览器理解您想要做什么,但是首先要问自己,您的标记的目的是什么,以存储您的数据(xml样式)或显示它。如果要呈现它,那么如果您想继续使用浏览器作为呈现引擎,那么您应该使用标准。祝你好运,如果我们都能定义我们的演示方案就太好了,好主意!
#6
1
getElementsByTagName fails me with custom tags. Example,
getElementsByTagName使用自定义标记失败。的例子,
<acme:mytag id="mytag">
<div id ="x">x</div>
<div id ="y">y</div>
<div id ="z">z</div>
</acme:mytag>
This fails with IE8 (Quirks Mode or Standard Mode)
这在IE8上是失败的(古怪模式或标准模式)
var mytag = document.getElementById('mytag'); // it's found
var mydivs = mytag.getElementsByTagName ('div'); // but this is always 0
Unless your html tag reads
除非你的html标签读取
<html XMLNS:acme>
...
</html>
#1
6
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.
原因之一是Internet Explorer(以及早期版本的Firefox)没有为未定义的标记提供退路,最终在样式和嵌套上都忽略它们。如果没有shiv,你的站点会在这些浏览器中崩溃。
#2
3
You can use your own tags, but the problem is that since they're not standard, browsers won't know that they may have matching closing tags. And of course, the document won't validate as proper HTML/X-HTML.
您可以使用自己的标记,但问题是,由于它们不是标准的,浏览器不会知道它们可能有匹配的结束标记。当然,文档不会作为适当的HTML/X-HTML进行验证。
<blah>
This is some <span>test</span> test text with another <bogus>tag</bogus> tag
within, which ends with a fake self-closing <tag />
</blah>
Browsers will see <blah>
, not now how to deal with it, and treat it as essentially "nothing" and ignore it. Then they'll happily parse away on to the next bit, and see some plain text, with a valid span inside. Eventually they'll reach the </blah>
and ignore that as well.
浏览器将看到
This is why Javascript and CSS had to support the opening HTML comment sequence as part of their respective language definitions:
这就是为什么Javascript和CSS必须支持开放的HTML注释序列作为它们各自语言定义的一部分:
<script type="text/javascript">
<!-- // <--actually a part of the javascript spec, treated as a comment.
alert('hey!');
//-->
</script>
When Javascript was first introduced, there were still MANY other browsers out there that were entirely unaware of Javascript, and so they'd ignore tags, and happily output your Javascript code. Ditto for CSS.
当Javascript刚开始引入时,仍然有很多浏览器完全不知道Javascript,所以它们会忽略标记,并愉快地输出Javascript代码。同上的CSS。
If you really need custom tags, you can produce the document as XML with your own DTD attached, and use XSLT to transform it into a valid HTML/X-HTML document.
如果您确实需要自定义标记,可以使用自己的DTD将文档作为XML生成,并使用XSLT将其转换为有效的HTML/X-HTML文档。
#3
1
The issue is that it would not validate and the new tags would simply be ignored.
问题是,它不会验证,新的标记将被忽略。
#4
1
Most browsers will just treat the tags as arbitrary (like how old browsers treat HTML5 tags). Nothing is stopping you from using your own tags, but it's not a well-accepted way to code HTML. HTML is supposed to use pre-defined tags.
大多数浏览器只会将标签视为任意的(就像旧的浏览器对待HTML5标签的方式一样)。没有什么能阻止您使用自己的标记,但这不是一种广为接受的编写HTML的方式。HTML应该使用预定义的标签。
If you're interested in coding with arbitrary tags, you could just go with XML. You can format XML with XSLT (used in a way similar to stylesheets, but much more powerful). Have a look here: http://www.w3schools.com/xml/xml_xsl.asp
如果您对使用任意标记进行编码感兴趣,可以使用XML。您可以使用XSLT来格式化XML(使用方式类似于样式表,但功能要强大得多)。看看这里:http://www.w3schools.com/xml/xml_xsl.asp
#5
1
What is the goal of the tags you chose? If your goal is to present information, then using divs and other presentation-oriented structures is great. Your tags look more like they are attempting to describe the actual data. If that is the case, then XML with XSLT transforms on the server side to output HTML for presentation markup is best. Remember that a browser is simply a rendering engine and it uses the HTML spec as it's blueprint of what to render for a given site. The browser doesn't need to understand the information like a "post" or "userInfo" because it has no context for undertsanding what to do from a rendering perspective with that information. CSS can help a browser understand what you want to do visually but ask yourself first whats the goal of having your markup that way, to store your data (XML-style) or to present it. If to present it, then you should go with the standards if you want to continue to use a browser as your rendering engine. Good luck, would be great if we could all define our presentation schemes though, fun idea!
您选择的标签的目标是什么?如果你的目标是呈现信息,那么使用divs和其他面向呈现的结构是很好的。您的标记看起来更像是试图描述实际数据。如果是这样,那么在服务器端使用XSLT转换的XML输出HTML作为表示标记是最好的。请记住,浏览器只是一个呈现引擎,它使用HTML规范作为给定站点呈现内容的蓝图。浏览器不需要像“post”或“userInfo”这样理解信息,因为它没有上下文来理解从呈现透视图中使用这些信息做什么。CSS可以帮助浏览器理解您想要做什么,但是首先要问自己,您的标记的目的是什么,以存储您的数据(xml样式)或显示它。如果要呈现它,那么如果您想继续使用浏览器作为呈现引擎,那么您应该使用标准。祝你好运,如果我们都能定义我们的演示方案就太好了,好主意!
#6
1
getElementsByTagName fails me with custom tags. Example,
getElementsByTagName使用自定义标记失败。的例子,
<acme:mytag id="mytag">
<div id ="x">x</div>
<div id ="y">y</div>
<div id ="z">z</div>
</acme:mytag>
This fails with IE8 (Quirks Mode or Standard Mode)
这在IE8上是失败的(古怪模式或标准模式)
var mytag = document.getElementById('mytag'); // it's found
var mydivs = mytag.getElementsByTagName ('div'); // but this is always 0
Unless your html tag reads
除非你的html标签读取
<html XMLNS:acme>
...
</html>