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

CSS

Aligning vertically elements in a horizontal ul

Hey guys,

I'm trying to create a horizontal navbar but I'm struggling to align everything vertically. After I inserted the little key icon I could never align the texts again properly. What I'm doing wrong?

Here's my code: https://codepen.io/catyard/pen/WMVGMY

Thank you

1 Answer

Steven Parker
Steven Parker
231,271 Points

Try setting "vertical-align" of "::before" pseudo-element to "top" instead of "bottom".

Hey Steven! Thank you!

Words are now aligned but I still can't align all elements to the center of the red bar :(

Steven Parker
Steven Parker
231,271 Points

Try adding " line-height: 1.5em;" to the ".prebar ul li" rule.

It worked! Thank you Steven!

I don't fully understand why, but I'll try to figure it out.

Steven Parker
Steven Parker
231,271 Points

Text within a given line-height is vertically centered, and one of the elements had expanded the height of the list, but the other items were still top-aligned with a normal height.