.info Device Info:
mark#info Mobile
p.desc Check if the device is bigger than 576 pixels. <br> Using media query inside JavaScript.<br>
code (min-width: 576px)
View Compiled
.info {
font-size: 18px;
font-weight: bold;
}
/*
CSS USED FOR THE TEMPLATE
*/
* {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
color: #252631;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100vh;
background-color: #efefef;
}
.desc {
max-width: 400px;
opacity: 0.6;
text-align: center;
line-height: 1.6;
}
View Compiled
const outputElement = document.getElementById("info");
const smallDevice = window.matchMedia("(min-width: 576px)");
smallDevice.addListener(handleDeviceChange);
function handleDeviceChange(e) {
if (e.matches) outputElement.textContent = "Bigger Than Mobile";
else outputElement.textContent = "Mobile";
}
// Run it initially
handleDeviceChange(smallDevice);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.