简体   繁体   中英

Disable css style for IE7 and IE8

I have style sheet file and would like to disable some css tags in it for IE7 and IE8 browsers, how to do that? I do not want to put these tabs in separated css file I would like to keep then in one file.

I'd recommend the approach taken by the HTML5 boilerplate, outlined here by Paul Irish . Basically, set up your document like this:

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->

You now have classes in place to accurately target only certain versions of IE. Your css will look like this:

.element { margin-bottom: 20px; }
.lt-ie8 .element { margin-bottom: 10px; } 

You then avoid CSS hacks, and can keep everything in a single stylesheet.

As @Daniel states, this is not disabling styles, but over-riding them. If for some reason you want to send styles to only modern browsers and newer IE, you could add another class to the final html tag above, and use that.

If you try to have specific style-sheets only for IE it goes like this:

<!--[if IE 8]><link rel="stylesheet" href="css/ie8.css" type="text/css" media="screen"><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="css/ie7.css" type="text/css" media="screen"><![endif]-->
<!--[if IE]><link rel="stylesheet" href="css/ie.css" type="text/css" media="screen"><![endif]-->

More about this here: How To Create an IE-Only Stylesheet

.element {  
    margin-bottom: 20px;  
    margin-bottom: 10px\9;  
} 

Info from here: http://www.impressivewebs.com/ie7-ie8-css-hacks/

You cannot disable them, but you can override them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM