Skip to content

Instantly share code, notes, and snippets.

@chrise86
Forked from emilbjorklund/breakpoints_via_css.html
Created October 29, 2013 10:32
Show Gist options
  • Save chrise86/7212214 to your computer and use it in GitHub Desktop.
Save chrise86/7212214 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<!--[if IE 8]> <html lang="sv-SE" class="no-js ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="sv-SE" class="no-js"> <!--<![endif]-->
<head>
<meta charset="UTF-8">
<title>Breakpoint detection test</title>
<style type="text/css" media="screen">
@media screen and (min-width: 320px) {
#page:after {
content: 'smallest'; /* represent the current width-bracket */
display: none; /* hide ALL THE THINGS */
}
}
@media screen and (min-width: 480px) {
#page:after {
content: 'small'; /* represent the current width-bracket */
}
}
@media screen and (min-width: 600px) {
#page:after {
content: 'large'; /* represent the current width-bracket */
}
}
@media screen and (min-width: 768px) {
#page:after {
content: 'largest'; /* represent the current width-bracket */
}
}
</style>
</head>
<body>
<div id="page">
<h1>Reload at different viewport widths to trigger script.</h1>
</div>
<script type="text/javascript" charset="utf-8">
(function(win){
var doc=win.document,
el,
pseudo;
if (win.getComputedStyle && doc.querySelector) {
el = doc.querySelector('#page');
pseudo = win.getComputedStyle(el, ':after').getPropertyValue('content');
if (pseudo) {
alert(pseudo);
}
}
})(this);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment