I am relatively new to CSS and I am experimenting with media queries. Despite following advice on various Stackoverflow posts and other websites, I am unable to make them work.
My goal is simple - to change the color of boxes when the screen width falls below a certain threshold.
Here is my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" name"viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css" type="text/css" media="screen">
</head>
<body>
<span class="boxes" id="b1">Box 1</span>
<span class="boxes" id="b2">Box 2</span>
<span class="boxes" id="b3">Box 3</span>
<span class="boxes" id="b4">Box 4</span>
<span class="boxes" id="b5">Box 5</span>
</body>
</html>
CSS file:
.boxes {
height: 200px;
width: 200px;
color: #FFF;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 80px;
margin: 20px;
top: 100px;
position: relative;
background-color: red;
}
@media only screen and (max-width:600px) {
.boxes {
background-color: #000000;
}
}
What I have tried so far:
* @media screen
without using the only
keyword in the CSS file.
* Removing media="screen"
from the html link tag.
* Using max-device-width
in the CSS file.
* Adding
media="only screen and (max-device-width: 600px)"
in the HTML link tag.
Despite all my efforts, nothing seems to be working. Can anyone point out what I might be missing?