简体   繁体   中英

How can i apply one css property in Internet Explorer

.sample{
   height:15px;
   width:15px;
   margin:10px;
   padding:10px;
   float:left:

   /* this one apply in ie only */
   border:1px solid #fff;
   /* this one apply in ie only */
}

I would recommend using an entirely separate IE-specific stylesheet, to isolate all of the nasty IE hacks you use. Then, in your HTML, you can use a conditional comment to load that stylesheet for IE only.

HTML

<html>
    <head>
        <!--[if IE]>
            <link rel="stylesheet" type="text/css" href="/css/ie-hacks.css">
        <![endif]-->
    </head>
    <body>
        <!-- ... --->
    </body>
</html>

ie-hacks.css

.sample{
   border:1px solid #fff;
}

Use a conditional comment in the head of your HTML document.

<!--[if IE 6]>
.sample {border:1px solid #fff;}
<![endif]-->

check out "conditional CSS comments"
http://www.quirksmode.org/css/condcom.html

You can add !ie after the style declaration, eg .sample {border:1px solid #fff !ie;} . This works on IE 6 and 7, but doesn't work in 8, unless you trick it into IE7 compatibility mode using <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" > (just make sure this appears before the CSS).

The cleanest solution though, is to include am IE-specific CSS file.

If you need to make more changes, and to keep your pages clean, I would recommend using a separate stylesheet for IE.

<!--[if IE]>
//place link to IE stylesheet here.
<![endif]-->

Then make the change inside of the IE stylesheet.

you can simply do the following give some charcter like # or so before it. Firefox ,chrome and other browsers ignore that line but IE executes that.

Give that line at the end of your css so that it will take care. Most of the developers use this hack for margin, padding issues in IE browser

.sample{
   height:15px;
   width:15px;
   margin:10px;
   padding:10px;
   float:left:

   /* this one apply in ie only */
   border:1px solid #fff;
  # border:2px solid #fff;
   /* this one apply in ie only */ for ie it treats as 2px.
}

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