My first responsive website project has hit a roadblock, as I struggle to understand how to implement media queries effectively.
Here's a snippet of my code...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Responsive Layout Test</title>
<!-- Media Query 1 -->
<link href="mobile.css" rel="stylesheet" type="text/css" media="screen (max-width:480px)" />
</head>
<body>
<div id="container">
<div id="header">
<div id="logo">
<a href="#"><img src="images/TalonLogo.png" alt="TalonLogo" /></a>
</div>
<div id="nav">
<ul>
<li><a href="#">Test</a></li>
<li><a href="#">Test</a></li>
<li><a href="#">test</a></li>
</ul>
</div>
</div>
<div id="info">
</div>
</div>
Regarding the CSS:
@media only screen
and (min-device-width: 320px)
and (max-device-width: 480px) {
/* Styles */
body {
width: 100%
margin: 0;
padding: 0;
}
#container {
width: 480px;
margin-left: auto;
margin-right: auto;
}
#logo {
max-width: 100%;
text-align: center;
}
#nav {
margin-top: 10.6%;
margin-left: 4.6%;
}
The issue arises when changing background colors between main and mobile style sheets... For example:
Main style sheet
body {
background: #fff;
}
however, in mobile.css file:
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
body {
background: #000;
}
This causes the entire screen to turn black instead of at the specified width of 480px. Any guidance on this situation?