views:

580

answers:

5

I want to put padding-right:10px to my style for only IE , but I don't want other browsers to render this padding. Any solution to define padding only for IE, but protected from Firefox, chrome, and others?

+8  A: 

Use conditional comments.

Edit: If you really really want to hack the CSS - which you shouldn't - use

* + HTML .myClass {}

Which will target IE7 (I don't know how this works with IE8 in either mode - so please don't do it.)

edeverett
other way please? I have tried _padding-right:10px but not work. thanks!
Sinal
conditional comment isn't _property. check the link he gave
streetpc
There is no other way. The "*+html" hack works for IE7 and IE8 in IE7-mode. What has "_padding-right:10px" to do with his answer?
x3ro
You should also check http://www.evotech.net/blog/2007/05/ie7-only-css-hacks-examples/
x3ro
+6  A: 

Conditional IE Rules.

<!--[if IE 6]>
<style type="text/css">
  /*For example, this creates special instructions for IE 6*/
  .myDiv { padding-right: 10px; }
</style>
<![endif]-->

Make sure to respect the flow of your rules. You'll want this value to override any previous padding-right value, so place this after your other rules. Or you can add !important after the rule, giving you:

<!--[if IE 6]>
<style type="text/css">
  .myDiv { padding-right: 10px!important;
</style>
<![endif]-->

Stackoverflow Archive:

Jonathan Sampson
A: 

we use

//padding-right: 10px;

I guess every special character is ignored by every other browser..

Tommy
A: 

At webdevout.net there is a very thorough article examining the pros and cons of CSS hacks.

Wabbitseason
A: 

Read this and check that solves your problem. http://praveenbattula.blogspot.com/2009/05/ie-hacking-apply-styles-only-to-ie.html

Rare Solutions