@media only screen and (min-width:765px) javascript code example
Example 1: js media query
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<p>If the viewport is less than, or equal to, 700 pixels wide, the background color will be yellow. If it is greater than 700, it will change to pink.</p>
<p><strong>Resize the browser window to see the effect.</strong></p>
<script>
function myFunction(x) {
if (x.matches) { // If media query matches
document.body.style.backgroundColor = "yellow";
} else {
document.body.style.backgroundColor = "pink";
}
}
var x = window.matchMedia("(max-width: 700px)")
myFunction(x) // Call listener function at run time
x.addListener(myFunction) // Attach listener function on state changes
</script>
</body>
</html>
Example 2: minimum width of different devices in html
body {
background: white;
}
@media screen and (min-width: 980px) {
body {
background: red;
}
}
@media screen and (max-width: 979px) {
body {
background: blue;
}
}
@media screen and (max-width: 500px) {
body {
background: green;
}
}