I have a school project where I am trying to align both an image and a menu in the center and middle. Here is my code on CodePen: LINK I will also share the code here:
HTML
<header>
<img id="logo" src="https://exampleimage.com/logo.jpg">
<ul id="menutop1">
<li><a href="#home">Home</a></li>
<li><a href="#news">News</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#about">About</a></li>
</ul>
CSS
body{
margin: 0;
}
header{
background-color: #171A21;
width: 100%;
height: 200px;
text-align: center;
}
#logo{
width: 250px;
height: 172px;
}
#menutop1 {
list-style-type: none;
overflow: hidden;
}
#menutop1 li {
float: left;
}
#menutop1 li a {
display: block;
color: #666;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
#menutop1 li a:hover:not(.active) {
background-color: #ddd;
}
The issue I'm facing is that the menu goes under the image and stays to the left of the page. I've tried all possible solutions but couldn't find one that works, can someone please help me out? I'm really stuck.
Thank you for your assistance and apologies for any errors in my English.
UPDATE
Thanks to Kamila O's suggestion, the menu is now positioned next to the image. However, I want it to be centered vertically as well. I added this code:
vertical-align: middle; height: 100%;
to the menu, but I don't think it's the best solution because when I set a background color on the menu just for testing purposes, I noticed this:
The menu overflows from the div. Does anyone know a better solution for this issue?