24

If I set the img's size to 100*100, the containing div will be like 100*106.

Where does that extra '6px' come from? How does this behavior fit to the standard?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Clyde
  • 1,482
  • 2
  • 10
  • 13

2 Answers2

35

@clyde; yes this is a natural behavior of image because img is an inline element so user agents leave some space for descender characters.

you can remove it with css:

img { display:block; } or img { vertical-align:bottom; }

FOR MORE CHECK THESE

https://developer.mozilla.org/en/Images,_Tables,_and_Mysterious_Gaps

Unwanted padding-bottom of a div

Community
  • 1
  • 1
sandeep
  • 91,313
  • 23
  • 137
  • 155
  • In addition, because the `img` element is inside an anchor (`a` element) it may have addional styles applied to it which cause the anchor to take more space than just the image alone. You may want to try `a img { border: none; } a:link {text-decoration: none; border: none}`. – Mikko Rantalainen Jul 01 '11 at 09:38
  • Thanks! Space for descending characters in inline elements! – Clyde Jul 02 '11 at 04:19
  • This was tripping me up this morning for far longer than I'd like to admit. Thanks for posting! – Ian Pitts Jan 03 '14 at 16:50
0

I think we need more code, especially CSS styles, but essentially the cascading part of CSS can easily flow inherited sizes downwards. If your A has a style of some extra padding or margin, then your final DIV will get it, too. And A is an inline element which often adds padding in anticipation of more content; turning A's to blocks often solves these kinds of issues, so I would try that first.

AlexanderJohannesen
  • 2,028
  • 2
  • 13
  • 26