Skip to content

Instantly share code, notes, and snippets.

@mikefowler
Created September 12, 2012 02:49
Show Gist options
  • Save mikefowler/3703935 to your computer and use it in GitHub Desktop.
Save mikefowler/3703935 to your computer and use it in GitHub Desktop.
Easy to maintain media query fallbacks for <=IE8
<!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>
/* 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;
}
#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