I have 2 ordered lists on the same page, which forces me to use class names for my <ul> and <li> tags. However, when I add the class name (in this case "topbar"), it moves my "Information" drop-down menu to the end of the menu. I wanted it to the left. When I remove the class name, it moves back to the right. The bottom codes are one with the class name, and one without. What am I doing wrong here?
Code: Select all
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="UIC BVIS Program Website">
<meta name="keywords" content="uic,bvis,biomedical visualization">
<meta name="author" content="Eric Ou">
<style>
ul.topbar {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li.topbar {float: left;}
li a, .dropbtn
{display: inline-block;
color: white;
text-align: center;
padding: 8px 14px;
text-decoration: none;}
li a:hover, .dropdown:hover .dropbtn
{background-color: #555;}
li.dropdown {display: inline-block;}
.dropdown-content
{display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);}
.dropdown-content a
{color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;}
.dropdown-content a:hover {background-color: #f1f1f1}
.show {display:block;}
</style>
</head>
<body>
<ul class="topbar">
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn" onclick="myFunction()">Information</a>
<div class="dropdown-content" id="myDropdown">
<a href="information.html">Program Requirements</a>
<a href="Lecture.html">Frank Armitage Lecture</a>
</div>
</li>
<li class="topbar"><a href="about.html">About</a></li>
<li class="topbar"><a href="History">History</a></li>
<li class="topbar"><a href="contact.html">Contact</a></li>
</ul>
<script>
function myFunction()
{document.getElementById("myDropdown").classList.toggle("show");}
window.onclick = function(e)
{if (!e.target.matches('.dropbtn'))
{var dropdowns = document.getElementsByClassName("dropdown-content");
for (var d = 0; d < dropdowns.length; d++)
{var openDropdown = dropdowns[d];
if (openDropdown.classList.contains('show'))
{openDropdown.classList.remove('show');}
}
}
}
</script>
</body>
</html>
Code: Select all
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="UIC BVIS Program Website">
<meta name="keywords" content="uic,bvis,biomedical visualization">
<meta name="author" content="Eric Ou">
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {float: left;}
li a, .dropbtn
{display: inline-block;
color: white;
text-align: center;
padding: 8px 14px;
text-decoration: none;}
li a:hover, .dropdown:hover .dropbtn
{background-color: #555;}
li.dropdown {display: inline-block;}
.dropdown-content
{display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);}
.dropdown-content a
{color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;}
.dropdown-content a:hover {background-color: #f1f1f1}
.show {display:block;}
</style>
</head>
<body>
<ul>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn" onclick="myFunction()">Information</a>
<div class="dropdown-content" id="myDropdown">
<a href="information.html">Program Requirements</a>
<a href="Lecture.html">Frank Armitage Lecture</a>
</div>
</li>
<li><a href="about.html">About</a></li>
<li><a href="History">History</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
<script>
function myFunction()
{document.getElementById("myDropdown").classList.toggle("show");}
window.onclick = function(e)
{if (!e.target.matches('.dropbtn'))
{var dropdowns = document.getElementsByClassName("dropdown-content");
for (var d = 0; d < dropdowns.length; d++)
{var openDropdown = dropdowns[d];
if (openDropdown.classList.contains('show'))
{openDropdown.classList.remove('show');}
}
}
}
</script>
</body>
</html>