Due to some circumstances, this blog is now up for sale, for more enquires contact: Plushista@gmail.com
RealcomBiz
Pin It

How to Target IE6, IE7, IE8, IE9, IE10 and IE11

by Unknown | Friday, October 24, 2014 | | 57 Comments

It gets frustrating when different versions of Internet Explorer displays our web pages differently due to the inconsistent rendering engine.

Sometimes, we might just think tweaking our code to render the same across different browser version is not that important, but that's a wrong idea. Many users don’t care what browser they are using as long as it browses the internet. Sadly, most of these users are on IE7, IE8, and IE9 because that is what comes installed on their PC. Luckily there are now several ways of targeting IE.



Conditional Comments

The simplest and almost the best way to target Internet Explorer is through conditional statement. The basic structure is the same as an HTML comment (<!-- -->). Therefore all other browsers will see them as normal comments and will ignore them entirely.

Example:

<!--[if IE]>
<link href="ie.css" rel="stylesheet">
<![endif]-->
<!--[if IE6]>
<style type="text/css">
/* styles for IE6 goes here */
</style>
<![endif]-->
<!--[if lt IE7]>
<style type="text/css">
/* styles for IE7 goes here */
</style>
<![endif]-->
<!--[if lte IE8]>
<style type="text/css">
/* styles for IE8 goes here */
</style>
<![endif]-->
<!--[if gt IE9]>
<style type="text/css">
/* styles for IE9 goes here */
</style>
<![endif]-->
<!--[if gte IE9]>
<style type="text/css">
/* styles for IE9 goes here */
</style>
<![endif]-->
<!--[if !IE]> -->
<style type="text/css">
/* styles goes here but should not appear in IE5-9 */
</style>
<!-- <![endif]-->


Note the special syntax:

  • <!--[if IE]> = all IE version
  • <!--[if IE9]> = IE9
  • <!--[if lt IE9]> = less than IE9
  • <!--[if lte IE9]> = less than or equal to IE9
  • <!--[if gt IE6]> = greater than IE6
  • <!--[if gte IE6]> = greater than or equal to IE6
  • <!--[if !IE]> -->  = content should appear in all browser except IE

Also, note that conditional comments were disabled in IE10+, so IE10 and up will not understand the test.


Conditional HTML Class

Another great way of targeting IE is to add a browser-unique class to the <html> element. Basicially, it checks if it is IE, then add a class to the html tag. So to target specific IE version, simply use the IE class as the parent selector (eg. .ie6, .ie7).

Example:

<!--[if IE]><![endif]-->
<!--[if lt IE 7 ]> <html lang="en" class="ie6"> <![endif]-->
<!--[if IE 7]> <html lang="en" class="ie7"> <![endif]-->
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html lang="en"><!--<![endif]-->
<!--[if !IE]><!--><html lang="en"><script>if(/*@cc_on!@*/false){document.documentElement.className+='ie10';}</script><!--<![endif]-->

As you might have noticed from the last line. Since IE10 does not support conditional statements, you can apply an ie10 class to the <html> element.

Then in your CSS you can strictly access your target browser, like so:

.ie6 {
    border:1px solid blue;
}
.ie7 {
    border:1px solid red;
}


CSS Hacks

With CSS hacks, you can target any IE version. Though, this method is not recommended because they are not valid CSS syntax. But if you only need to change one or two properties to make IE happy, then I don't see any harm in using the underscore or asterisk hack directly in your stylesheet. However, if there are a handful of changes, be sure to use conditional comments.

The logic is simple:

  • IE9, IE8 or below: to target Internet Explorer 9, 8 and below in CSS, append a backlash and 9 (\9) to the end of the style you want to apply.
  • IE7 or below: add an asterisk (*) before the CSS property.
  • IE6: add an underscore (_) before the property.

Example:

/* IE6 */
body { _color: blue; }

/* IE7, IE6 */
body { *color: blue; } /* or #color: blue */

/* IE9, IE8, IE7, IE6 */
body { color: blue\9; }

/* IE8, IE7 */
body { color/*\**/: blue\9; }

/* IE7, IE6 -- acts as an !important */
body { color: blue !ie; }

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
/* IE10+ CSS styles go here */
}


The last CSS media query rules which target IE10 and IE11 is a valid CSS rule. Here’s the technique: we create a media query using -ms-high-contrast, in which you place your IE10+ specific CSS styles. Because -ms-high-contrast is Microsoft-specific (and only available in IE10+), it will only be parsed in Internet Explorer 10 and greater.

Hacking your CSS may seem a quick fix for getting your styles to work across browser types, but it can harm sometimes. Imagine if the new release of Firefox or Safari support properties prepended with the asterisk (*) hack. They probably never would for compatibility reasons, however, if they did, that could potentially ruin a portion of your layout. That's why I recommend the first two options.



Go Social:

Subscribe For Free Updates!

*Please confirm the email sent to your inbox after clicking "Sign Up!".

57 comments : Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.

  1. This was super helpful. Just saved me on a project at work. Stupid lack of conditional comment support. >.>

    ReplyDelete
  2. Like i only know that the latest was IE8 haha! too old for new updates in technology



    Heard about Olympia Kitchen Remodel

    ReplyDelete
  3. Demonstrat to them whole your products which must be moved to the new destination.

    Packers and Movers Bangalore @ http://www.11th.in/packers-and-movers-bangalore.html
    Packers and Movers Noida @ http://www.11th.in/packers-and-movers-noida.html
    Packers and Movers Ghaziabad @ http://www.11th.in/packers-and-movers-ghaziabad.html
    Packers and Movers Chennai @ http://www.11th.in/packers-and-movers-chennai.html

    ReplyDelete
  4. I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people
    - fnaf

    ReplyDelete
  5. Thanks a lot for sharing. To get all the latest bollywood news,gossips and rumors,just check
    imo beta apk

    ReplyDelete

  6. http://getpackers.com/packers-and-movers-bangalore/
    http://getpackers.com/packers-and-movers-bangalore-to-hyderabad/
    http://getpackers.com/packers-and-movers-bangalore-to-kerala/
    http://getpackers.com/packers-and-movers-bangalore-to-gurgaon/






    ReplyDelete
  7. For Diwali Gifts,Visit us at:
    Diwali Chocolates Hampers @ http://www.diwaligiftz.com/diwali-chocolates-hampers.php
    Diwali Sweet Hampers @ http://www.diwaligiftz.com/diwali-sweets-hampers.php
    Diwali Dry Fruits Hampers @ http://www.diwaligiftz.com/diwali-dryfruits-hampers.php

    Diwali gift hampers # http://www.diwaligiftz.com/diwali-gift-hampers.php
    Diwali gifts for corporates # http://www.diwaligiftz.com/diwali-gifts-for-corporates.php
    send diwali gifts online # http://www.diwaligiftz.com

    ReplyDelete
  8. Golden 1 Center, the Sacramento Kings' new $557 million arena, has set a new benchmark for NBA facilities.At the main entrance on the arena’s northwest side, five towering glass doors fold up garage-style — together standing 50 feet tall and 150 feet wide — to create the NBA’s first indoor-outdoor venue.“California is all Golden State Warriors Jerseys about indoor-outdoor living,” Kings owner Vivke Ranadivé told SportsBusiness Journal. “The architects presented many different ideas and when they showed Stephen Curry Jerseys me that idea, that was it. That was something that became the exclamation point for the arena.”Team officials are working NBA Jerseys closely with the NBA to develop guidelines for keeping the doors open for Kings games. As it stands, there are Kyrie Irving Shoes no league rules for playing games in an indoor-outdoor setting.For the Kings’ two preseason games at Golden 1 Center, the http://www.cheapnbajerseyscustom.com team kept the doors open for the first half and closed them for the second half. In both situations, the L.A. Clippers Jerseys team recorded temperature and humidity levels every 15 minutes and submitted the data to the league office.
    Nobody should've needed Paul George Jerseys a reason to watch Russell Westbrook play basketball — not ever, and certainly not this season.He, alone, is reason enough; Kevin Durant Jerseys it seems counterintuitive, but the Westbrook-centric Thunder are more compelling than their previous iteration. Kevin Durant is gone, and OKC Kevin Durant Shoes will be worse for it, but if nothing else, we knew what he and Westbrook looked like together. We knew Lebron James Jerseys

    ReplyDelete
  9. Thinking of an iOS 10 Jailbreak? Well, you should be! Yalu Jailbreak has been released for iPhone and iPad devices.


    You can now jailbreak iOS 10 using the new tool on Windows or MacOS to get Cydia installed on your iOS devices.

    ReplyDelete
  10. aharashtra board will publish the ssc result 2017 soon

    ReplyDelete
  11. The maharashtra hsc result will be available on the official website that is www.mahresult.nic.in.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Acording to our reports C. Raveendranath Education Minister kerala announced that 82% of students have cleared the 2017 SSLC exams.
    kerala sslc results 2017
    kerala 10th class sslc results 2017

    ReplyDelete
  14. I was working and suddenly I visits your site frequently and recommended it to me to read also. The writing style is superior and the content is relevant. Thanks for the insight you provide the readers!

    http://word-cookies-answers.com

    ReplyDelete
  15. I was more than happy to uncover this great site. I need to to thank you for your time due to this fantastic read!! I definitely enjoyed every bit of it and I have you bookmarked to see new information on your blog.
    for latest updates about sports . please visit
    Sportleadz
    Champions Trophy 2017
    Champions Trophy 2017 Hghlights
    Champions Trophy 2017 Fixtures
    Champions Trophy 2017 Live Scores

    ReplyDelete
  16. Thanks on your marvelous posting! I really enjoyed reading it, you’re a great author.Please visit here:
    Packers And Movers Jaipur

    ReplyDelete
  17. Your article is very good and useful, thank you very much for this content.
    windows movie maker

    ReplyDelete
  18. Interesting article! Thank you for sharing them! I hope you will continue to have similar posts to share with everyone!
    html color

    ReplyDelete
  19. I enjoyed over read your blog post. Your blog have nice information, I got good ideas from this amazing blog. I am always searching like this type blog post. I hope I will see again
    bloxorz

    ReplyDelete
  20. Packers And Movers Kolkata is recognized as a business manager providing wide-ranging and differentiate service appearance as well as Relocation Shifting, Logistics and Transportation, Facilities managing, strategy & Designing services.html: Packers And Movers Pune

    ReplyDelete
  21. I really enjoyed reading your blog, you have lots of great content.Please visit here: html:Packers And Movers Trichy

    ReplyDelete

  22. What's Going down i am new to this, I stumbled upon this I have discovered It positively useful and it has aided me out loads. I am hoping to contribute & aid different users like its helped me. Great job.
    Watch Wimbledon live
    wimbledon stream

    ReplyDelete
  23. Packers and Movers Indore - Call 09303355424, Local Household Shifting in Indore, Domestic Home Relocation from Indore. International Home Relocation from Indore, Office Shifting within Indore, Car and Bike Transportation from Indore, Safe Packing and Moving Services,
    Packers and Movers Indore
    Packers and Movers Gurgaon
    Packers and Movers Kolkata
    Packers and Movers Mumbai
    Packers and Movers Delhi
    Packers and Movers Jaipur
    Packers and Movers Raipur
    Packers and Movers Pune
    Packers and Movers Ahmedabad
    Packers and Movers Indore Blog

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete
  25. Our point is to bring marital innovation less expensive for each and every Indian for the wedding and expand their odds of finding appropriate Indian Grooms and Brides.

    Jeevanrahi is an Indian Matrimonial Sites offer administrations of Hindu, Muslim, Christian, Sikh and many more.
    Indian Matrimonial Sites
    Best Matchmaker Sites
    Free Matrimonial Sites Our point is to bring marital innovation less expensive for each and every Indian for the wedding and expand their odds of finding appropriate Indian Grooms and Brides.

    Jeevanrahi is an Indian Matrimonial Sites offer administrations of Hindu, Muslim, Christian, Sikh and many more.
    Indian Matrimonial Sites
    Best Matchmaker Sites
    Free Matrimonial Sites

    ReplyDelete
  26. Thanks for sharing this and also check website

    ReplyDelete
  27. its very valuable information for students
    LIC insurance

    ReplyDelete
  28. This is very informative and interesting for those who are interested in blogging field.
    Alice Jenifer this blogger profile will lead you to the free Gift Card Generator 2019.

    ReplyDelete
  29. top packers and movers in noida delhi and gurgaon providing all over india transportation best services for more information call us on our number or mail us 9024332029, 9910303792
    Agarwal Packers and movers Noida
    Agarwal Packers and movers Noida

    ReplyDelete
  30. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really usefull I put things off too much

    ReplyDelete
  31. Students require Civil Law Assignment Help to comprehend and find out about the different classifications of the wrongdoings, and the punishment and case procedures identified with them.

    ReplyDelete
  32. Just dial +1(830) 476-2055 from wherever you are across the country to contact our reliable and trusted Quickbooks support center. You will get authentic solutions for your Quickbooks related issues to fulfill your bookkeeping requirements. Quickbooks Contact Number

    ReplyDelete
  33. discover this r3t69u7c01 replica louis vuitton louis vuitton replica bags neverfull 7a replica bags wholesale this page k9s14n1k67 replica bags in london replica bags reddit view publisher site o7o92a9v95 zeal replica bags

    ReplyDelete

Recent Posts

Let's Connect

Site Links

Copyright © 2014 RealcomBiz. All Rights Reserved.
Powered by Blogger