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
ezekielenejeta
2,665 PointsWhat is the best way to style two paragraphs vertically aligned to center
Good day all, i am having some challenge styling two paragraphs to vertically align to center. pls how best can i style it with some padding, margin and border.
2 Answers
Luciano Bruzzoni
15,518 PointsAssuming that you don't want both paragraphs to be next to each other, there are different ways to accomplish this. you could wrap the paragraphs in a div and then use css to give it a width and the margin to auto; like: <div id ="center"> <p>paragraph 1</p> <p>paragraph 2</p> </div>
and in your css
center{
width: 300px;
margin: 0 auto;
}
you can then add the padding and border to the same css rule. like:
center{
width: 300px;
margin: 0 auto;
margin-top: 50px;
border: solid black;
border-radius: 25%;
padding: 10px;
}
hope that helped!
edit: the paragraphs should be inside a div tag, for some reason the forum is not showing it, and when selecting the center id in your css use the pound sign, again that's not showing up either on the code bits.
Jeff Lemay
14,268 PointsYou can add display:inline-block and vertical-align:middle to the paragraphs. Or you could wrap the paragraphs in a div and give that div display:table and then give the paragraphs display:table-cell with vertical-align:middle.