I've written a solution for this myself. All you need is two different CSS files (one for modern browsers and one for older IE browsers) and a cleaver mixin.
Create a second SASS file which Compass can watch and call the file something like oldIE.scss
. Copy all the imports from you original SASS file (styles.scss or whatever) to this file. Then put a new variable in both of them: $compile-IE
. Set the values like this:
styles.scss
$compile-IE: false;
@import "all your other imports"
oldIE.scss
$compile-IE: true;
@import "all your other imports"
Compass will now create two different CSS files for you. You can place them in the HEAD
of your Markup like this:
<link type="text/css" href="styles.css" rel="stylesheet" media="all" />
<!--[if (gte IE 6) & (lte IE 8)]>
<link type="text/css" href="oldIE.css" rel="stylesheet" media="all" />
<![endif]-->
Once you have the two files in place, you can start writing SASS with your breakpoints thanks to the following mixin:
// ----- Media-queries ----- //
$breakpoints: S 480px, M 600px, L 769px;
@mixin bp($bp) {
// If compile-IE is true (IE8 <=) then just use the desktop overrides and parse them without @media queries
@if $compile-IE {
@content;
}
// If compile-IE is false (modern browsers) then parse the @media queries
@else {
@each $breakpoint in $breakpoints {
@if $bp == nth($breakpoint, 1) {
@media (min-width: nth($breakpoint, 2)) {
@content;
}
}
}
}
}
Call the mixin as following:
p {
color: blue;
font-size: 16px;
@include bp(L) {
font-size: 13px;
}
}
Now, if the variable $compile-IE
is false
(for modern browsers) the output will be this:
p {
color: blue;
font-size: 16px; }
@media (min-width: 768px) {
p {
font-size: 13px;
}
}
And when the variable $compile-IE
is true
(for older IE versions) the output will be this:
p {
color: blue;
font-size: 16px;
font-size: 13px;
}
Because the font-size: 13px
is the parsed after the font-size: 16px
the styles used for larger viewports (like bp L) will override the default mobile styling.
Hope this will help for you! :)