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

Why do we need the 'display: inline-block'?

I found out that if I omit the 'display: inline-block' I still have the same result so why do we need that piece of code anyway? Thanks in advance !

1 Answer

I'm not sure which specific task you are referring to but the general use of inline-block is so that you can set height and width without using an entire block.

As you know, a block element will let you manage the height and width to whatever your specifications are and as a block element it ensures there are line breaks before and after the element.

An inline element does not require breaks before or after the element but you can not directly modify the height of the inline element.

Inline-block gives you the best of both worlds. You can manage height and width but it doesn't require an entire block.

That is a common scenario but there are actually a few other reasons that you may need to use inline-block. I'd recommend reading this short but informative article.

You'll find that sometimes it may appear that you get the same results regardless of each one you use but there are actually some important differences in how they display and can affect other elements.