rowefx
rowefx

Reputation: 265

IE8 not rendering HTML correctly

I'm having some issues in IE8 that I have never seen before. Essentially the problem is that there is a navigation menu that has styles inside of the following markup:

      <section class="top-bar-section">

        <ul class="left">

          <li>
            <a href="#">Link</a>
            <a href="#">Link</a>
            <a href="#">Link</a>
            <a href="#">Link</a>
            <a href="#">Link</a>
          </li>

        </ul>

      </section>

    </nav>

However in IE8 I'm looking at the dom tree and the HTML is not being rendered as above. Below is a picture comparing the dom tree in both IE8 and Chrome.

IE8 and Chrome Dom tree comparision

You can see that the nav, section and UL elements are being closed without being parent and child elements of one another. This is having a causing a problem with the CSS rules as they require being child and parents to allow the css rules to be applied.

Upvotes: 0

Views: 1315

Answers (3)

Rafa Romero
Rafa Romero

Reputation: 2716

This is because you are using an HTML5 tag as section is, and of course IE8 doesn't support HTML5 tags as ou can see in CanIUse

Internet Explorer 8 and earlier versions, do not support the <section> tag.

You need something that "enable" HTML5 iN IE8 as HTML5 Shiving or Modernizr

HTML5Shiv is a JavaScript workaround to enable styling of HTML5 elements in versions of Internet Explorer prior to version 9

Modernizr is a small JavaScript library that detects the availability of native implementations for next-generation web technologies, i.e. features that stem from the HTML5 and CSS3 specifications

Upvotes: 1

Alex
Alex

Reputation: 11245

You need HTML5Shiv script for IE 8- to use HTML5 tags. The main fix is in creating HTML5 section element in the head of document:

document.createElement("section")

This somehow lets the CSS engine know that elements with that name exist.

The trick is that calling document.createElement("section") will suddenly cause IE to recognize the section element. No one knows why, but it works and you don’t even need to use the node returned by that function.

From this article, it explain why IE8- needs this script.

Upvotes: 1

Spudley
Spudley

Reputation: 168685

The <section> tag is not supoprted by IE8.

It is one of the new HTML5 tags and was not invented yet when IE8 was released. Therefore IE8 knows nothing about it.

IE8 default to not rendering unknown elements.

In order to make IE8 understand the <section> tag and other new HTML5 tags, you need to use the html5shiv polyfill script. This script helps IE8 to recognise these tags as being valid HTML, and thus to render them correctly.

You can also use Modernizr, which has additional functionality for helping deal with old browsers, and also includes the HTML5shiv functionality.

The alternative, of course, is simply to not use the new HTML5 tags; just use a <div> instead, and IE8 will work just fine with that without any javascript hacks.

Upvotes: 2

Related Questions