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

Unwanted whitespace

So i'm playing around with this image overlay and for some reason right at the bottom there is some unwanted whitespace here is the codepen link can someone help me out

codepen link

4 Answers

Set image to display:block.. that seems to fix the space underneath

LIFESAVER!!! do you know the reason why this fixes it though ?

Like Chris Warr suggested, setting your image to display: block is the solution you're looking for. However, you can also set font-size: 0; in your container, which will also eliminate the whitespacing (not a suggested solution though). Font-size?! Yeah, I'll explain. Keep reading.

The reason you got the whitespace is because it was being treated as an inline element. Inline elements are generally treated as elements without set dimensions and thus they will not push other content into new rows on the page (hence the name "inline"). Inline elements are generally given to things you would arrange within a paragraph, such as strong, anchor, i, etc.

So to answer your latter question, the reason you got the white-space under your image is the same reason text have whitespace between lines. Your image was essentially being treated as text (or any other inline element) and so your browser was applying the default whitespacing for inline-elements to your image.

So now you know why setting a font-size to zero is another possible solution to this issue. Basically, font with zero dimensions also have zero whitespacing.

Oh, and you should know that the img element is actually inline by default, so it may be a good habit to always check and see if the display: block property applies in your situation. From my experience, it usually does.

Hope this helps!

Good luck.

EDIT: Just realized that line-height: 0; is another possible solution, which is even better than setting font-size to zero. (though I'd still suggest display: block).

Try setting the image width to 100% as opposed to max-width:100%.

tried that has no effect :(

In general I find inline elements to be unreliable with padding,margins, width, height etc Found this old article about inconsitency:

http://www.maxdesign.com.au/articles/inline/

Thanks a lot man i'll read into it