Created
May 5, 2012 11:15
-
-
Save calderon/2601635 to your computer and use it in GitHub Desktop.
Solution to Sub-pixel IE's bug with SASS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// !!! NOT TESTED WITH WIDTH OR MARGIN NEGATIVE VALUES | |
// IE correction | |
@function correction($container-width){ | |
@return (0.5 / $container-width) * 100%; | |
} | |
//Fixed % to IE | |
@function pc($container-width: 0,$percentage: 0){ | |
@if $percentage == auto or $percentage == 0{ | |
@return $percentage; | |
}@else{ | |
@return ( $percentage - correction($container-width) ); | |
} | |
} | |
@mixin width($container-width: 0,$percentage: 0){ | |
.ie6 &, | |
.ie7 &{ | |
width: pc($container-width,$percentage); | |
} | |
width: $percentage; | |
} | |
@mixin margin($container-width:0, $ptop: 0, $pright: 0, $pbottom: 0, $pleft: 0){ | |
margin: $ptop $pright $pbottom $pleft; | |
.ie6 &, | |
.ie7 &{ | |
margin: pc($container-width,$ptop) pc($container-width,$pright) pc($container-width,$pbottom) pc($container-width,$pleft); | |
} | |
} | |
// EXAMPLE | |
#example{ | |
$width: 49; | |
width: 49px; | |
background-color: green; | |
overflow: hidden; | |
.title{ | |
background-color: red; | |
width: #{$width}px; | |
height: 50px; | |
} | |
.boxexample{ | |
@include width($width,25%); | |
@include margin($width,20%,auto,0,0); | |
height: 50px; | |
float: left; | |
background-color: blue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment