I am having trouble aligning an image and a hamburger menu within the Header. When clicked, the list appears at the bottom of the image in a horizontal line, but it is listing vertically on the right of the image instead. How can I resolve this issue? Should I place my list and image within different divs?
Here is the HTML code:
<header>
<img src="images/ace_in_the_hole.png" alt="Ace in the Hole Weekend Marathon Logo">
<ul class="topnav" id="myTopnav">
<li><a href="#about">About</a></li>
<li><a href="#courseinfo">Course Information</a></li>
<li><a href="#register">Registration</a></li>
<li><a href="#contact">Contact</a></li>
<li class="icon">
<a href="javascript:void(0);" onclick="myFunction()">☰</a>
</li>
</ul>
</header>
And the CSS code:
img {
width: 50%;
height: 50%;
float: none;
}
header {
padding-bottom: 2em;
}
/* Styles for the top navigation list */
ul.topnav {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: white;
}
/* Display list items side by side */
ul.topnav li {float: left;}
/* Styling for the links inside list items */
ul.topnav li a {
display: inline-block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s;
font-size: 17px;
}
/* Hover effect for links */
ul.topnav li a:hover {background-color: lightgray;}
/* Responsive design for small screens */
@media screen and (max-width: 680px) {
/* Styles for image and list items */
img {
float: left;
height: 5em;
}
ul.topnav li {display: none;}
ul.topnav li.icon {
float: right;
display: inline-block;
}
}
/* JavaScript function to toggle responsive class on click */
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}