This is my first time using media queries.
I am building a navigational bar for a website, and I would like it to change from a navigational bar to a dropdown list after a certain device width is reached (like in https://www.w3schools.com/howto/howto_js_topnav_responsive.asp). I have incorporated W3's design into my own, however, it seems like I cannot get my navigational bar to change.
Here is my relevant CSS:
... Additional CSS Settings...
.navigation-bar{
width:100%;
list-style-type: none;
margin:0;
padding:0;
background-color: #DDDDDD;
overflow:hidden;
}
.navigation-bar li{
display:inline;
}
.navigation-bar a{
text-decoration: none;
font-size: 120%;
color: #000000;
padding-left:1%;
padding-right:1%;
padding-top:0.5%;
padding-bottom:0.5%;
display:inline-block;
}
.navigation-bar a:hover{
background-color:#999999;
}
.navigation-bar a.active{
background-color: #999999;
}
.navigation-bar .icon{
display:none;
}
... Additional CSS Settings..
@media screen and (max-width: 900px){
.navigation-bar a:not(:first-child) {display: none;}
.navigation-bar a.icon{
float:right;
display: block;
}
}
@media screen and (max-width: 900px) {
.navigation-bar.responsive {position: relative;}
.navigation-bar.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.navigation-bar.responsive a {
float: none;
display: block;
text-align: left;
}
}
Here is my relevant HTML:
<html>
<head>
<meta charset = "utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport" />
<title>Title</title>
<link rel=stylesheet type="text/css" href="CS File">
</head>
<body>
<h1><a href="index.html">Website Title</a></h1>
<ul id="navigation" class="navigation-bar">
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
<li><a href="#">Item 6</a></li>
<li><a href="#">Item 7</a></li>
<li><a href="javascript:void(0);" class="icon" onclick="myFunction()"><i class="fa fa-bars"></i></a></li>
</ul>
<script type="text/javascript" src="JS File"></script>
<script type="text/javascript" src="css3-mediaqueries.js"></script>
</body>
</html>
Here is my relevant JS:
function myFunction() {
var x = document.getElementById("navigation");
if (x.className === "navigation-bar") {
x.className += " responsive";
} else {
x.className = "navigation-bar";
}
}
With this, my navigational bar is not responding at all. I am wondering if I am missing anything that I need to include in my code, or if I am missing something. I'm thinking that it might have something to do with my navigation being within a list, but I am not sure how that would affect the code, nor how to create a workaround it.
W3's Example Code: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_topnav