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 trialLuca Di Pinto
8,051 PointsClickable areas in the header links
Hi everybody, I have one trouble! Why Guil set display:block to .name a and .main-nav a? Couldn't he use display:inline-block? Shouldn't it work as same as display:block? I cannot understand the difference!!
Thanks in advance
4 Answers
Kristian Egebæk-Carlsen
9,809 PointsIf he sets the links and to inline-block, he would not be able to expand the box around the link. If you notice the video, when he sets the top and bottom padding on an inline object, it will not work. But when he change the links to display:block; the white area around the link expands on the top and bottom.
Kristian Egebæk-Carlsen
9,809 PointsSome styles does not apply to inline elements, nor if they are inline-block. Thats why you separate the links and display them as blocks only.
Luca Di Pinto
8,051 PointsBut doesn't inline-block work as block one? So which is the difference between these two? Guil said the inline-block is the same as inline but you can style it as the block one! Mumble mumble!!!
Ricardo Saito
6,689 PointsYes, Luca, inline-block elements can be styled the same way as block elements. In this case, the difference between using either of them is the initial size of the element:
-If you use "display: inline-block", the element will take the size of its content (in this case, the links' text), so you might need to add further CSS declarations to stretch it, especially if the parent element has fixed width or height values;
-If you use "display: block", the element automatically becomes the same size of its parent, which is much better for expanding a link's area.
This difference is more noticeable in the "name" element, because it has a fixed width of 240px. If you change the display value to "inline-block", you can see how there's a little space in the left and right sides of the box that doesn't become clickable.
Peace!
ywang04
6,762 PointsThanks for your answers. It is clear to me.