Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Safari to recognize <main> HTML 5

It appears as though some fairly recent versions of Safari don't support the <main> HTML5 element. (I have tested Safari 5.1.9 on Snow Leopard, and mobile Safari running on IOS 4 thus far). Is there a way to get Safari to recognize the <main> element (like a shiv)?

I have thrown together some example code below. When viewed in an affected version of Safari the green <main> box does not appear, if I were to add more text it would flow outside of the <main> element as if it were not even there.

HTML:

<body>
    <main>
        <nav id="bar"></nav>
        <p>Lorem Ipsum</p>
    </main>
</body>

CSS:

main{
width:800px;
height:800px;
background-color:#0C0;
}

#bar{
width:300px;
height:400px;
float:left;
background-color:#09F;
}
like image 459
Elle Avatar asked Jul 15 '13 18:07

Elle


1 Answers

Most browsers display unknown elements as if they were display:inline by default, so popping this CSS in somewhere should do it:

main {
    display: block;
}

E.g.

main {
    display: block;
    width: 800px;
    height: 800px;
    background-color: #0C0;
}
  • http://jsfiddle.net/PeF8u/ — green area not visible
  • http://jsfiddle.net/PeF8u/1/ - green area visible

(I tested in Safari 6.0.5 on Mountain Lion.)

Sitepoint have a good write-up of the <main> element: http://www.sitepoint.com/html5-main-element/

There’s also a great Stack Overflow answer that describes in a general way how to get new HTML5 elements working (for some definition of “working”) in older browsers: https://stackoverflow.com/a/13949253/20578

like image 71
Paul D. Waite Avatar answered Oct 18 '22 21:10

Paul D. Waite