4

I have a class:

.banner {
  padding: 2% 33% 2% 20%;
}

In Chrome always normal, but for IE 10+ normal style: 2% 22% 2% 23%. How to define padding style for normal working in all these browsers?

Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90
Ivan Tikhonov
  • 304
  • 2
  • 17
  • 2
    Try to avoid fixing your CSS for specific browsers; it tends to be unreliable. Instead, try to track down where the extra padding in IE is coming from. – Blazemonger Aug 03 '17 at 15:28
  • Yeah, modern browsers very rarely present the need for this sort of thing. You should figure out what's not standard about your layout. – isherwood Aug 03 '17 at 19:21

3 Answers3

1
/* Chrome 28+ (also affects Safari and MS Edge now) */
@supports (-webkit-appearance:none) { /* Needed styles */ }

/* Firefox (any) */
_:-moz-tree-row(hover), .selector { /* Needed styles */ }

/* Internet Explorer 11+ */
_:-ms-fullscreen, :root .selector { /* Needed styles */ }

/* Internet Explorer 10+ */
_:-ms-lang(x), .selector { /* Needed styles */ }

/* Also Internet Explorer 10+ */
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  /* Needed styles */
}

/* Internet Explorer 9+ */
_::selection, .selector { /* Needed styles */ }

/* Safari 6.1+, Chrome for iOS */
@media screen and (min-color-index: 0) and(-webkit-min-device-pixel-ratio: 0) { @media {
  /* Needed styles */
}}

If you need IE9-

For IE9- you can apply conditional comments and add style or link tag there. Also they allow to add conditional markup for browsers.

<!--[if IE]><p>You are using Internet Explorer.</p><![endif]-->

<!--[if IE 7]><p>Welcome to Internet Explorer 7!</p><![endif]-->
<!--[if !(IE 7)]><p>You are not using version 7.</p><![endif]-->

<!--[if gte IE 7]><p>You are using IE 7 or greater.</p><![endif]-->
<!--[if (IE 5)]><p>You are using IE 5 (any version).</p><![endif]-->
<!--[if (gte IE 5.5)&(lt IE 7)]><p>You are using IE 5.5 or IE 6.</p><![endif]-->
<!--[if lt IE 5.5]><p>Please upgrade your version of Internet Explorer.</p><![endif]-->

Vadim Ovchinnikov
  • 13,327
  • 5
  • 62
  • 90
  • don't understand how to apply styles for Chrome 28+, where i should type my class name in `@supports (-webkit-appearance:none) { /* Needed styles */ }` – Ivan Tikhonov Aug 03 '17 at 19:06
  • like this `@supports (-webkit-appearance: none) { .my-class-name { color: red; } }`. – Vadim Ovchinnikov Aug 03 '17 at 19:51
  • 1
    @IvanTikhonov By the way I have a bit outdated data. Now `@supports (-webkit-appearance: none) { .my-class-name { color: red; } }` works even for Safari and MS Edge. – Vadim Ovchinnikov Aug 04 '17 at 08:33
0

you should avoid fixing your CSS for specific browsers, but if you really want to experiment it there are multiple solutions. you can find a lot of useful code here http://browserhacks.com/

fixing your CSS for specific browsers:

Selector hacks

/* IE6 and below */
* html #one { color: red }

/* IE7 */
*:first-child+html #two { color: red } 

/* IE7, FF, Safari, Opera  */
html>body #three { color: red }

/* IE8, FF, Safari, Opera (Everything but IE 6,7) */
html>/**/body #four { color: red }

/* Opera 9.27 and below, Safari 2 */
html:first-child #five { color: red }

Attribute hacks

.class {
  width:200px; /* All browsers */
  *width:250px; /* IE */
  _width:300px; /* IE6 */
  .width:200px; /* IE7 */
}

/* IE6 */
#twentyseven { _color: blue }

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

/* Everything but IE6 */
#twentynine { color/**/: blue }

/* IE6, IE7, IE8 */
#thirty { color: blue\9; }

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

Conditional comments

<!--[if IE]>
    According to the conditional comment this is IE<br />
    <link href="ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE 6]>
    According to the conditional comment this is IE 6<br />
<![endif]-->
<!--[if IE 7]>
    According to the conditional comment this is IE 7<br />
<![endif]-->
<!--[if IE 8]>
    According to the conditional comment this is IE 8<br />
<![endif]-->
<!--[if IE 9]>
    According to the conditional comment this is IE 9<br />
<![endif]-->
<!--[if gte IE 8]>
    According to the conditional comment this is IE 8 or higher<br />
<![endif]-->
Liam
  • 6,009
  • 4
  • 39
  • 53
  • 1
    Cool solution, especially `/* Opera 9.27 and below, Safari 2 */`. You are copy-pasting CSS hacks from very old resource. By the way no Chrome hack (probably this data is published before 2008). – Vadim Ovchinnikov Aug 03 '17 at 15:43
0

I resolved my task using bellow styles in strong order:

/* IE 9+ */
_::selection, .baner{
padding: 2% 33% 2% 20%;
}

/* Chrome */
.baner{
-webkit-padding-after: 2%;
-webkit-padding-before: 22%;
-webkit-padding-start: 2%;
-webkit-padding-end: 23%;
}
Ivan Tikhonov
  • 304
  • 2
  • 17