Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rid of space underneath inline-block image [duplicate]

Tags:

html

css

layout

How do I get rid of the space between the bottom of the image and the wrapper, while keeping the image as inline-block? Why is this happening?

http://jsfiddle.net/dJVxb/2/

HTML:

<div id="wrapper"> <img src="https://twimg0-a.akamaihd.net/profile_images/1735360254/icon_reasonably_small.jpg" >                  </div> 

CSS:

​#wrapper {     background:green; } img {     display:inline-block;      margin:0; } 

enter image description here

like image 433
Yarin Avatar asked May 16 '12 05:05

Yarin


People also ask

How can gap under the image be removed?

Display Property: The most commonly used solution is used to change the display property of the <img> tag inside the <div> container from default 'inline' value to 'block' using display : block property.


2 Answers

Write vertical-align:top;. Write like this:

img {     display:inline-block;      margin:0;     vertical-align:top; } 

Check this http://jsfiddle.net/dJVxb/4/

like image 185
sandeep Avatar answered Sep 29 '22 21:09

sandeep


That added space is there to make room for descenders were there inline text as well. Descenders are parts of letters that reach down, like in 'y' and 'g'.

If you need to retain a vertical-align property of center or baseline, you can fix this by setting your line-height to 0.

like image 38
CourtDemone Avatar answered Sep 29 '22 21:09

CourtDemone