When can I safely use the new
element in HTML5?

前端 未结 4 1061
南旧
南旧 2021-02-02 09:05

On the 16th December, a HTML5 extension specification for the

element was submitted to the W3C under something called an editors draft. The abstract is
4条回答
  •  清歌不尽
    2021-02-02 09:53

    For now, I would be careful about usng it.

    For the future of the proposal, what really matters is implementation in browsers. In particular, because

    is a proposed block level element, it will require a change to the HTML5 parser implementation as well as giving it the default ARIA role of main.

    Without the default ARIA role, there is no point to the element, although using it now in preparation for that is a reasonable approach.

    The parser change does require a modicum of care though. Remember that the

    tag is optional. Now suppose you decide that before your "main" content you want a paragraph of preamble. You could write:

    
    
      

    This is my page preamble ...

    My main content ...
    A story ...

    If and when browsers implement the

    element, the
    tag will automatically close the

    element and in the DOM, the

    element and the

    element will be siblings of one another. The
    element and its content will be a child of the
    element. i.e. The DOM will be:

    HTML
     +--HEAD
     +--BODY
         +--P
         |  +--This is my page preamble ... 
         +--MAIN
             +--My main content ...
             +--DIV
                 +--A story 
    

    However, right now in browsers, the

    becomes a child element of the

    element, and while "My main content ..." is a child of the

    element, the
    element is not. i.e. the DOM has this structure:

    HTML
     +--HEAD
     +--BODY
         +--P
         |  +--This is my page preamble ...
         |  +--MAIN
         |      +--My main content ... 
         +--DIV
            +--A story 
    

    Now, of course, this is easily avoided by explicitly using a

    tag, on the preamble paragraph, but it is a trap for the unwary.

提交回复
热议问题