Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Layout Basics CSS Layout Project Creating and Styling the Layout Containers

Jonathan Buford
Jonathan Buford
2,065 Points

Why does adding display: block; padding: 10px 15px; result in moving the name and link to center?

Wow. I really feel like I should know this. I usually make things harder than they are but I've been on this for 3 days and have just started reverse engineering Guil's code in the zip file so I could at least learn something. Not knowing where to start and then having questions turn into more questions...I've been studying CSS and HTML for 9 months now and it has me worried;( These items were already showing on their own line before display: block.

Ugh. I feel like even my questions are not good, but I need you guys!

3 Answers

Padding and Display properties are two different aspects so I dont think must be centering an object, https://www.w3schools.com/cssref/playit.asp?filename=playcss_display&preval=block follow this link to know more about DISPLAY.

The padding doesn't necessarily have anything to do with it; it's the "display: block;"

Jesse Sandate
Jesse Sandate
985 Points

yeah exactly... The display property with a value of block makes the a-tags, which are normally inline elements, into block size. Thats why each link's hover area is the entire width of the viewport, essentially that is what is centering the text in the menu.