I have the following HTML code:
<header>
<h1>Title</h1>
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</nav>
</header>
I am looking to turn this into a single line on the top of my web page by floating right the <nav>
.
However, because the <h1>
has a much bigger font size than the <li>
elements the text gets misaligned. I want the elements to be aligned on the baseline. In a picture:
Note the red line for the baseline. This is what I have right now:
#float, #nofloat { width: 300px; }
ul, h1, nav, p { margin: 0; padding: 0; }
h1 {
display: inline-block;
font-size: 3rem;
}
nav { display: inline-block; }
ul { list-style-type: none; }
ul > li { display: inline; }
ul > li:after { content: " | "; }
ul > li:last-child:after { content: ""; }
#float nav { float: right; }
<p>Everything is aligned to baseline before floating:</p>
<div id="nofloat">
<header>
<h1>Title</h1>
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</nav>
</header>
</div>
<p>But after floating it's messed up:</p>
<div id="float">
<header>
<h1>Title</h1>
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</nav>
</header>
</div>