Currently, most browsers support HTML5. However, some lower version browsers have some problems with HTML5 support.
all browsers, and unrecognizable elements will be automatically processed as inline elements. Therefore, you can use the following method to teach the browser to handle "unknown" HTML elements.
HTML5 defines 8 new HTML semantic elements. All these elements are block-level elements.
In order to allow older versions of browsers to display these elements correctly, you can set the display attribute of CSS to block:
header, section, footer, aside, nav, main, article, figure { display: block; }
:
<!DOCTYPE html><html><head><meta charset="utf-8">
<title>为 HTML 添加新元素</title>
<script>document.createElement("myElement")</script>
<style>
myElement{
display: block;
background-color: #ddd;
padding: 50px;
font-size: 30px;
}
</style>
</head>
<body>
<h1>我的第一个标题</h1>
<p>我的第一个段落。</p>
<myElement>我的第一个新元素</myElement>
</body>
</html>
We can use the "HTML5 Enabling
JavaScript", "shiv" created by Sjoerd Visscher to solve this problem:
<!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->
<!--[if lt IE 9]> <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"></script> <![endif]-->
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>渲染 HTML5</title> <!--[if lt IE 9]> <script src="http://apps.bdimg.com/libs/html5shiv/3.7/html5shiv.min.js"> </script> <![endif]--></head><body><h1>我的第一个HTML5页面</h1> <article>Hello,world!</article> </body> </html>
The above is the detailed content of Detailed explanation of HTML5 browser compatibility solutions. For more information, please follow other related articles on the PHP Chinese website!