Skip to content

Instantly share code, notes, and snippets.

@c3ry5
Created March 17, 2014 09:13
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 c3ry5/9596169 to your computer and use it in GitHub Desktop.
Save c3ry5/9596169 to your computer and use it in GitHub Desktop.
How to get the media query of your page
body #currentMediaQuery {
display: none;
}
@media only screen and max-width 479px {
body #currentMediaQuery {
font-family: xxs;
}
}
@media only screen and min-width 480px {
body #currentMediaQuery {
font-family: xs;
}
}
@media only screen and min-width 768px {
body #currentMediaQuery {
font-family: sm;
}
}
@media only screen and min-width 992px {
body #currentMediaQuery {
font-family: md;
}
}
@media only screen and min-width 1310px {
body #currentMediaQuery {
font-family: lg;
}
}
var getMediaQuery = function () {
var id = "currentMediaQuery",
elem, state, div;
if(!document.getElementById(id)) {
div = document.createElement("div");
div.id = id;
document.body.appendChild(div);
}
elem = document.getElementById(id);
if (elem.currentStyle) {
state = elem.currentStyle.fontFamily;
} else if (window.getComputedStyle) {
state = window.getComputedStyle(elem).getPropertyValue("font-family");
}
return state;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment