ROKAF
ROKAF

Reputation: 119

My Media Query does not work. Included Meta tag; link rel link

Beginner coder here. I'm trying to make breakpoints for my website for mobile devices so that my website properly fits in tiny screens. I just wanted to check to see if the background-color would change if I shrunk the width of the viewport, but no changes occur. Maybe I'm just blind to a simple mistake?

body {
	margin: 0;
	background-color: #4f4d4d;
	overflow-x:hidden;
	width: 100%;
	height: auto;
}

ul {
	margin-top: -80px;
	list-style-type: none;
}

li {
	font-size: 25px;
    float: right;
    font-weight: bold;
}

li a {
	display: block;
	text-decoration: none;
	text-align: center;
	font-family: sans-serif;
	color: white;
	border-left: 1px solid white;
	padding: 23px;
}

li a:visited {
	text-decoration: none;
	color: white;
	font-family: sans-serif;
}

li a:hover:not(.active) {
	background-color: #333;
}


#header {
	position: relative;
	width: 100%;
	height: 875px;
	background-image: url(../images/bg.jpg);
	background-repeat: no-repeat;
	background-size: 100% 100%;
}

#nav {
	width: 100%;
	height: 75px;
	background-color: black;
}

#logo {
	width: 75px;
	height: 75px;
}

#logo_text {
	position: absolute;
	display: inline;
	top: -10px;
	left: 80px;
	font-size: 30px;
	font-family: sans-serif;
	color: white;
	font-weight: bold;
}

#welcome_text_div {
	position: absolute;
	width: 1000px;
	height: 300px;
	top: 25%;
	left: 0;
	right: 0;
	margin: auto;
}

#welcome_text {
	color: white;
	font-family: sans-serif;
	text-transform: uppercase;
	font-weight: bold;
	font-size: 90px;
	text-align: center;
}

#welcome_under_text {
	color: white;
	font-family: sans-serif;
	text-align: center;
	font-weight: bold;
	margin-top: -80px;
	font-size: 25px;
}

#alumni_div {
	position: relative;
	height: 800px;
	width: 95%;
	margin-right: auto;
	margin-left: auto;
	top: 100px;
	margin-bottom: 50px;
}


.alumni_link:link {
	text-decoration: none;
}

.alumni_link:visited {
	color: white;
}

.alumni_link:hover {
	color: grey;
}

#alumni_1 {
	position: absolute;
	width: 25%;
	height: 100%;
	background-color: black;
	right: 77%;
}

#alumni_2 {
	position: absolute;
	width: 25%;
	height: 100%;
	background-color: blue;
	right: 51%;
}

#alumni_3 {
	position: absolute;
	width: 25%;
	height: 100%;
	background-color: red;
	left: 50.5%;
}

#alumni_4 {
	position: absolute;
	width: 25%;
	height: 100%;
	background-color: orange;
	left: 77%;
}

.alumni_text {
	font-family: sans-serif;
	font-weight: bold;
	font-size: 35px;
	margin-top: 300px;
	color: white;
	text-align: center;
}

.graduate_text {
	font-family: sans-serif;
	font-weight: bold;
	font-size: 20px;
	color: white;
	text-align: center;
}
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>CLC Website</title>
	<link rel="stylesheet" href="main1.css">
	<link rel="stylesheet" media="mediatype and|not|only (media feature)" href="mystylesheet2.css">
</head>
<body>
	<div id="header">
		<div id="nav">
			<img src="../images/logo.png" id="logo" alt="logo">
			<p id="logo_text">CLC</p>
			<ul>
				<li><a href="#">Contact Us</a></li>
				<li><a href="#">Professors</a></li>
				<li><a href="#">Courses</a></li>
				<li><a href="#">About</a></li>
				<li><a href="#">Home</a></li>
			</ul>
		</div><!--/nav-->

		<div id="welcome_text_div">
			<p id="welcome_text">The Best Offer</p>
			<p id="welcome_under_text">Truth evades a single definition and true understanding requires a comparative perspective</p>
		</div><!--/welcome_text_div-->
	</div><!--/header-->

		<div id="alumni_div">
			<div id="alumni_1">
				<a href="#" class="alumni_link"><p class="alumni_text">Alumni Name <br> Class of 15</p><p class="graduate_text">Graduate School</p></a>
			</div>

			<div id="alumni_2">
				<a href="#" class="alumni_link"><p class="alumni_text">Alumni Name <br> Class of 14</p><p class="graduate_text">Company A</p></a>
			</div>

			<div id="alumni_3">
				<a href="#" class="alumni_link"><p class="alumni_text">Alumni Name <br> Class of 13</p><p class="graduate_text">Company B</p></a>
			</div>

			<div id="alumni_4">
				<a href="#" class="alumni_link"><p class="alumni_text">Alumni Name <br> Class of 12</p><p class="graduate_text">Company C</p></a>
			</div>
		</div><!--/alumni_div-->
</body>
</html>

@media only screen and (max-width: 1024px) {
	body {
	margin: 0;
	background-color: white;
	overflow-x:hidden;
	width: 100%;
	height: auto;
    }
}


@media only screen and (max-width: 767px) {
	body {
	margin: 0;
	background-color: red;
	overflow-x:hidden;
	width: 100%;
	height: auto;
    }
}

@media only screen and (max-width: 480px) {
	body {
	margin: 0;
	background-color: blue;
	overflow-x:hidden;
	width: 100%;
	height: auto;
    }  
}

Upvotes: 0

Views: 62

Answers (2)

Johannes
Johannes

Reputation: 67768

it works as expected here. Did you put you media queries BELOW all the other CSS rules? If not, they can be overridden by the subsequent rules.

ADDITION/EDIT (moved up from the comments): In the HTML, take out media="mediatype and|not|only (media feature)" from the reference to the second stylesheet.

Upvotes: 0

Nutshell
Nutshell

Reputation: 8537

See this fiddle

Brackets are missing, it's more like this :

@media only screen and (max-width: 1024px) {
    body {
      margin: 0;
      background-color: white;
      overflow-x:hidden;
      width: 100%;
      height: auto;
    }
}


@media only screen and (max-width: 767px) {
    body {
      margin: 0;
      background-color: red;
      overflow-x:hidden;
      width: 100%;
      height: auto;
    }
}

@media only screen and (max-width: 480px) {
    body {
      margin: 0;
      background-color: blue;
      overflow-x:hidden;
      width: 100%;
      height: auto;
    }
}

Upvotes: 3

Related Questions