Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Brett Miller
1,739 PointsHow do I get my h1 to center vertically in my header/navbar?
Here is a simplified version of my header
<header>
<h1>Title</h1>
<nav>
<ul>
<li>List</li>
<li>List</li>
<li>List</li>
</ul>
</nav>
</header>
header {
margin: 0;
background-color: #aaa;
height: 150px;
width: 100%;
}
h1 {
display: inline-block;
padding: 10px;
font-size: 1em;
}
nav {
display: inline-block;
width: 40%;
float: right;
}
I want my h1 on the left but centered vertically in the header element. I tried margin: auto 0; A beginner answer is preferred. Thanks in advance.
1 Answer

Steven Parker
242,284 PointsVertical centering can be a bit tricky.
There are a few ways to do it, here's an example using positioning (my favorite):
header {
position: relative; /* establish the positioning context for the h1 */
}
h1 {
margin: 0;
position: absolute;
top: 50%; /* halfway down */
transform: translateY(-50%); /* minus half the header height */
}
Brett Miller
1,739 PointsBrett Miller
1,739 PointsIt finally works! Thanks for the quick reply.