Skip to content

Instantly share code, notes, and snippets.

@jbgutierrez
Created January 25, 2012 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbgutierrez/1675776 to your computer and use it in GitHub Desktop.
Save jbgutierrez/1675776 to your computer and use it in GitHub Desktop.
Media querys IE fallback
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Media querys IE fallback</title>
<style>
p {
color: blue;
}
@media only screen and (max-width: 1024px) {
p {
color: green;
}
}
.lt1024 p {
color: green;
}
</style>
</head>
<body>
<!--[if lt IE 9]>
<script>
(function() {
function addClass(element, className){
if (element.className.indexOf(className) === -1) {
element.className = element.className + ' ' + className;
}
}
function removeClass(element, className){
element.className = element.className.replace(new RegExp('(^|\\s)' + className + '(?:\\s|$)'), '$1');
}
function addMediaQueryFallback(){
if (document.body.clientWidth < 1024) {
addClass(document.body, 'lt1024');
} else {
removeClass(document.body, 'lt1024');
}
};
addMediaQueryFallback();
document.body.onresize = addMediaQueryFallback;
})();
</script>
<![endif]-->
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment