Created
September 12, 2012 02:49
-
-
Save mikefowler/3703935 to your computer and use it in GitHub Desktop.
Easy to maintain media query fallbacks for <=IE8
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
<!doctype html> | |
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]--> | |
<!--[if IE 8]><html class="no-js lt-ie9" lang="en"> <![endif]--> | |
<!--[if gt IE 8]><!--><html class="no-js" lang="en"> <!--<![endif]--> | |
<head> | |
<title>Example</title> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<meta name="viewport" content="width=device-width"> | |
<link rel="stylesheet" type="text/css" href="css/style.css"/> | |
</head> | |
<body> | |
<div id="container"></div> | |
</body> | |
</html> |
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
/* Mobile-first Styles */ | |
#container { | |
width: 100%; | |
} | |
/* Progressive enhancement for browsers that support @media */ | |
@media only screen and (min-width: 480px) and (max-width: 768px) { | |
#container { | |
width: 960px; | |
margin: 0 auto; | |
} | |
} | |
/* Fallback static layout for <= IE8 */ | |
.lt-ie8 #container { | |
width: 960px; | |
margin: 0 auto; | |
} |
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
#container { | |
// Mobile Styles | |
width: 100%; | |
// Progressive Enhancement | |
@include respond-to('desktop') { | |
width: 960px; | |
margin: 0 auto; | |
} | |
} | |
@mixin respond-to($size) { | |
// For 'desktop' sizes, a media query is used for browsers | |
// that support them. For browsers that don't (IE8 and below), | |
// the same styles are output inside a 'lt-ie9' class, applied | |
// on the <html> element via conditional tags. | |
@if $size == 'desktop' { | |
@media only screen and (min-width: 768px) { | |
@content | |
} | |
.lt-ie9 & { | |
@content | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment