我什么时候可以安全地使用新的< main>元素在HTML5中? [英] When can I safely use the new <main> element in HTML5?

查看:95
本文介绍了我什么时候可以安全地使用新的< main>元素在HTML5中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

12月16日,< main> 元素的HTML5扩展规范为提交给W3C的一个叫做编辑草案的东西。摘要如下:


本规范是对HTML5规范[HTML5]的扩展。
它定义了一个元素用于识别文档的主
内容区域。 HTML5
规范中的所有规范性内容,除非本规范明确覆盖,否则
是本规范的基础。



主要元素形式化识别
文档的主要内容部分的常见做法是使用诸如
'content'和'main'等id值。它还定义了一个HTML元素,它体现了WAI-ARIA [ARIA]里程碑式角色= main的语义和功能



<例如:

 <! - 其他内容 - > 

< main>

< h1>苹果< / h1>
< p>苹果是苹果树的果核。< / p>

<文章>
< h2> Red Delicious< / h2>
< p>这些鲜红色的苹果是许多
超市中最常见的。< / p>
< p> ...< / p>
< p> ...< / p>
< / article>

<文章>
< h2> Granny Smith< / h2>
< p>这些多汁的青苹果为
苹果派做了很好的填充。< / p>
< p> ...< / p>
< p> ...< / p>
< / article>

< / main>

<! - 其他内容 - >

这里有所有的信息,我觉得我应该开始将它合并到网页中。据我现在所知,HTML5规范只是渐进式的,新功能被狂奔到规范而没有升级。我想这意味着浏览器会在可能的时候开始实施 - 问题是,这需要多长时间,我如何知道所有浏览器都支持它?我应该像现在这样构建它,然后使用polyfill?

解决方案

支持<




  • 新的浏览器已经足够支持所有其他新的HTML5引入的容器元素了。将会支持它。

  • 旧版浏览器会让你对它进行设计,因此它是 display:block ,并给你它的视觉效果

  • 如果没有JavaScript填充程序(它的工作方式与所有其他新的容器元素的填充方式完全相同),老版本的IE根本不支持它。



  • when取决于您需要的浏览器支持级别以及您是否愿意依赖JS shim。


    On the 16th December, a HTML5 extension specification for the <main> element was submitted to the W3C under something called an editors draft. The abstract is as follows:

    This specification is an extension to the HTML5 specification [HTML5]. It defines an element to be used for the identification of the main content area of a document. All normative content in the HTML5 specification, unless specifically overridden by this specification, is intended to be the basis for this specification.

    The main element formalises the common practice of identification of the main content section of a document using the id values such as 'content' and 'main'. It also defines an HTML element that embodies the semantics and function of the WAI-ARIA [ARIA] landmark role=main.

    Example:

    <!-- other content -->
    
    <main>
    
      <h1>Apples</h1>
     <p>The apple is the pomaceous fruit of the apple tree.</p>
    
     <article>
     <h2>Red Delicious</h2>
      <p>These bright red apples are the most common found in many
      supermarkets.</p>
      <p>... </p>
      <p>... </p>
      </article>
    
      <article>
      <h2>Granny Smith</h2>
      <p>These juicy, green apples make a great filling for
      apple pies.</p>
      <p>... </p>
      <p>... </p>
      </article>
    
    </main>
    
    <!-- other content -->
    

    It's got all the info in there and I feel I should start incorporating it into web pages. As far as I know now, the HTML5 spec is just progressive with new features been "bolted" on to the spec with no upgrade. I guess that means the browsers will start implementing it when they can - the question is, how long does this take and how do I know all browsers support it? Should I just build it like so for now and resort to a polyfill?

    解决方案

    Support for <main> will be much like support for any other new container element introduced in HTML 5.

    • New enough browsers will support it.
    • Older browsers will let you style it so it is display: block and give you the visual effects of it
    • Older versions of IE won't support it at all without a JavaScript shim (which will work in exactly the same way as the ones for all the other new container elements).

    The "when" depends on what level of browser support you need and how willing you are to depend on a JS shim.

    这篇关于我什么时候可以安全地使用新的&lt; main&gt;元素在HTML5中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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