Home arrow HTML arrow Page 2 - html5shiv and the section Element
HTML

html5shiv and the section Element


If you’re eager to start using the new elements that come bundled with HTML5, but worry about whether or not Internet Explorer will allow them to render properly, leave your fears behind and take a look at “html5shiv”, a lightweight JavaScript library that adds HTML5 support to Microsoft’s browser by utilizing the “createElement()” DOM method. In this third part of a series we will be learning to use the handy <section> element.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 7
April 20, 2011
TABLE OF CONTENTS:
  1. · html5shiv and the section Element
  2. · Using Multiple HTML5

print this article
SEARCH DEVARTICLES

html5shiv and the section Element - Using Multiple HTML5
(Page 2 of 2 )



While the example above showed - in a nutshell - how simple is to use the <section> element with “html5shiv”, there’s plenty of room for implementing a few additional improvements. As I said in the preceding segment, one that can come in handy is adding multiple <section> tags.

The following code sample demonstrates how to achieve this in a snap: 

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Example using html5shiv with the header, nav and multiple section elements</title>
<!--[if lt IE 9]>
<script src="
http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
body {
    padding: 0;
    margin: 0;
    background: #000;
    font: 0.8em Arial, Helvetica, sans-serif;
    color: #000;
}
h1 {
    font-weight: normal;
    font-size: 2.1em;
}
h2 {
   font-weight: normal;
   font-size: 1.8em;
}
p {
    margin: 0 0 15px 0;
}
#wrapper {
    width: 500px;
    margin: 0 auto;
    background: #b0b000;
}
header {
    display: block;
    padding: 15px;
    background: #b9524d;
}
nav {
    display: block;
    height: 30px;
    padding: 10px 0 0 80px;
    background: #0080ff;
}
nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
nav ul li {
    float: left;
    width: 130px;
}
nav ul li a {
    font-weight: bold;
    color: #fff;
    text-decoration: none;
}
section {
    display: block;
    padding: 15px;
    background: #b0b000;
}
</style>
</head>
<body>
<div id="wrapper">
    <header>
        <h1>Header section</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed posuere ullamcorper lacus et sollicitudin. Morbi ultrices condimentum lacus, sit amet venenatis purus bibendum sit amet.</p>
    </header>
    <nav>
        <ul>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
        </ul>
    </nav>
    <section>
        <h2>Generic section 1</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed posuere ullamcorper lacus et sollicitudin. Morbi ultrices condimentum lacus, sit amet venenatis purus bibendum sit amet.</p>
    </section>
    <section>
        <h2>Generic section 2</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse auctor commodo risus, et ultrices sapien vestibulum non. Maecenas scelerisque quam a nulla mattis tincidunt. Etiam massa libero, pharetra vel laoreet et, ultrices non leo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed posuere ullamcorper lacus et sollicitudin. Morbi ultrices condimentum lacus, sit amet venenatis purus bibendum sit amet.</p>
    </section>
</div>
</body>
</html>

Mission accomplished. At this point, the structure of the previous web page is definitively a bit closer to a “real world” use case, as now it defines two generic areas, which have been semantically represented through a couple of <section> elements. With this neat markup already set, the last step that must be taken is to try the page using Internet Explorer.

That worked really smooth, right? In a few easy steps, I managed to create a decent web page layout using some HTML5 elements, which are correctly rendered by Internet Explorer. If this doesn’t convince you to try out “html5shiv”, I guess nothing will. So, don’t get stuck in the stone age of web design and give the library a try. You won’t regret it, trust me.  

Final Thoughts

In this third part of the series, I showed you a couple of examples of how to take advantage of the functionality provided by “html5shiv”, in order to use the <section> HTML5 element in a cross-browser manner. The process was very straightforward, which means that you shouldn’t have major difficulties replicating it when building your own web pages.

While the page layout designed so far will be seamlessly displayed on Internet Explorer, it still lacks some things that are present in more realistic scenarios. As you may have noticed, the layout doesn't have a side bar or even a decent footer. To fix up the first of these issues, in the next tutorial I’ll be adding a side column, which (unsurprisingly) will be semantically reflected via an <aside> HTML5 tag.    

As usual, don’t miss the next part!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
HTML ARTICLES

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials