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 trialUnsubscribed User
4,479 PointsWhy doesn't padding on anchor elements push out the height of the containing nav element?
Why doesn't the padding on the navigation anchor elements push out the height of the containing nav element?
The anchor elements have padding 10px right and left, and 15px top and bottom, which extends out over the top and bottom of the containing nav element?
3 Answers
Szabolcs Szána
6,961 PointsHi,
nav a { display: block; }
Unsubscribed User
4,479 PointsI did not know that padding for an element could sit outside a containing element. But as you say, to maintain the width and height of an element I need to declare it as, or give it the values of, a block element.
Thanks for your help guys.
Yevgeniy Alexeyev
3,591 Points<span>, <a>, <img> An inline element does not start on a new line and only takes up as much width as necessary. http://www.w3schools.com/html/html_blocks.asp
If you need to add padding, margin, width or height to inline object that affect surrounding objects, you need to make it block object.
Yevgeniy Alexeyev
3,591 PointsYevgeniy Alexeyev
3,591 PointsTry to add "display:block" to "nav a" element