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 CSS Layout Basics Controlling Layout with CSS Display Modes Using Inline-Block to Set Width, Height, Top and Bottom Margin and Padding

Dimitris Karatsoulas
Dimitris Karatsoulas
5,788 Points

Why the change of margin-top property applies both on name and main-nav.

  1. On the 2:05 mark of the video the margin-top property of .name is changed to 50px (line 113 of CSS code), this doesn't only apply on .name but also on .main-nav. They both seem to have the same margin from the top. Why does that happen? Since they are different elements shouldn't they also have different margins?

1 Answer

issa Mohamed
issa Mohamed
7,373 Points

I can only think of it as because .main-nav and .name are both displayed as inline-block meaning inline-block elements are effectively treated as block. Block-level elements respect both horizontal and vertical margins once margin-top is applied to .name that margin spans across the full width of the block taking any inline elements like .main-nav down 50px. As .main-nav is on the same line as .name

Dimitris Karatsoulas
Dimitris Karatsoulas
5,788 Points

Thank you for your response, this does explain that behaviour.