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
eslam said
Courses Plus Student 6,734 PointsVertical align
I want to know how to professionally vertical align elements here the code and my question :
<header>
<div id="header-content">
<h1>Dada</h1>
<p>Art movement</p>
</div>
</header>
i centered the text vertically like that :
padding-top:20%;
it worked but it`s kinda messy i feel like its not the proper way to vertically align elements, specially that when i tried to use 50% it wasnt 50 at all, i also dont know why.
6 Answers
Unsubscribed User
3,325 PointsIn that case this might be able to help you.
eslam said
Courses Plus Student 6,734 Pointsi want to center elements inside the div, i want the h1 and h2 to be centered vertically and horizontally, horinzontal align is not a problem since i can use text-align:center but what about the vertical align ?
eslam said
Courses Plus Student 6,734 Pointsis my question that hard ?
Unsubscribed User
3,325 PointsBoth the h1 and p elements are centered vertically, as the div element is only as tall as the content within it demands it to be. Look at this codepen to see what I mean.
eslam said
Courses Plus Student 6,734 Pointsyea but if the header height is more then the content itself the content will stay the same, it will not be centered vertically
eslam said
Courses Plus Student 6,734 Pointsthank you mike i used the following :
display:flex;
justify-content: center;
align-items: center;
Sargon Gabriel
2,618 PointsSargon Gabriel
2,618 Pointsyou want to vertically align the whole div ?