I've been grappling with this issue. I'm interested in exploring various methods to vertically center elements in navigation using semantic HTML. Specifically, I'd like my logo aligned left and the navigation menu aligned right.
I attempted to use float on the nav element, but it caused the logo to break alignment and prevented vertical centering. Even after employing clearfix, I haven't been able to successfully center both the logo and nav vertically. Can someone offer guidance on this matter? And could you please provide a detailed explanation of your solution? Additionally, if feasible, can you demonstrate alternative approaches to vertically aligning the logo (on the left) and nav (on the right) within the same framework as my current HTML?
Here is the code snippet for reference: https://codepen.io/yortz/pen/pQdKWd
HTML
<!-- HEADER -->
<header>
<!-- LOGO -->
<a href="#"><img id="site-logo" src="http://lorempixel.com/190/25/" alt="Bookworm"></a>
<nav>
<ul class="clearfix">
<li><a href="#">About</a></li>
<li><a href="#">Articles</a></li>
<li><a href="#">News</a></li>
<li><a href="#">Get in Touch</a></li>
</ul>
</nav>
</header>
CSS
* {
box-sizing: border-box;
}
/* HIGHLIGHTING NAVIGATION ELEMENTS */
header {
background-color: #ccc;
}
nav {
background-color: aqua;
}
/* CENTERING NAVIGATION */
header {
width: 100%;
}
#site-logo,
nav {
display: inline-block;
vertical-align: middle;
}
nav ul {
list-style-type: none;
padding-left: 0;
}
nav ul li {
display: inline-block;
}
nav ul li a {
border: 1px solid red;
padding: 10px 15px;
display: block;
text-decoration: none;
}
nav ul li a:hover {
background-color: red;
color: #fff;
}
/* CLEAR FLOATS */
.clearfix::after {
content: "";
display: table;
clear: both;
}
Your assistance would be greatly appreciated. Thank you!