6

I have this annoying space under my picture for no reason. I'm using www.getskeleton.com as the framework.

HTML code

<div class="four columns bottom">
  <div class="box">
    <img src="images/picture.png" title="" alt="">
  </div>
</div>

CSS code

.box{
  border: 1px solid #bfbfbf; /* ---- Border OUTSIDE*/
}

Here there is the space under the picture

Andy
  • 4,538
  • 2
  • 26
  • 34
dasmikko
  • 696
  • 2
  • 8
  • 29

7 Answers7

11

Although I'm sure this has since been resolved, I believe none of these answers are correct (or at least, the link from the "accepted" answer is dead).

The way to deal with this spacing issue (and why it isn't set in util libraries like normalize I'm not sure) is vertical alignment of the image. This'll solve it for HTML pages when using the HTML 5 doctype. Oddly, when using e.g., HTML 4.01 doctype, images will not exhibit this errant space below behaviour.

The fix:

img {
  vertical-align: top;
}

I hope that helps someone who may have run into this problem.

Edit: Some extra info I noticed after writing this and subsequently researching why normalize doesn't set alignment on the img tag; the default alignment for images is vertical-align: baseline; - that's the behaviour which introduces the space underneath. Normalize's author believes this behaviour is consistent cross-browser, and so has decided not to 'normalize' this. I suppose that makes sense if you wanted text sitting next to an image to align properly with any subsequent lines of text. Some people also prefer to use vertical-align: middle as opposed to top to address this issue - so you can vary this as you wish.

However, regarding baseline alignment, in the case where I had an image that was so big that it was higher than the line-height, I'd probably be floating it or some other behaviour anyway... but there you go.

I've used the vertical-align stuff for a while now without any incident. But as always, do ensure you test for any repercussions for images no longer being aligned to the baseline.

Mike Hopkins
  • 1,011
  • 1
  • 11
  • 13
2

Try this:

.box img {
    display: block;
    padding: 0px;
    margin: 0px;
}
qwerty
  • 5,166
  • 17
  • 56
  • 77
1

Try this: .box { font-size: 0; }

BoomyJee
  • 61
  • 2
  • 8
0

Your image need to be floated. Try this:

    #yourimage{
        float: left;}
Bruno Monteiro
  • 712
  • 6
  • 22
0

As mentioned, more information would help a lot but i have no doubt that it is padding that is causing the border to go out of the image, reason put very simply being

margin pushes outside the element
padding pushes inside the element

as it were.

Fix then:

.box {
    padding-bottom: 0px;
}
//to be sure that the image doesn't have any padding, even though OP said the .box img fix didn't help
.box img {
    margin-bottom: 0px;
}
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
0

It's an age old quirk - the whitespace from your line formatting is causing the gap. Add <br /> after the image.

thinice
  • 700
  • 5
  • 19
0

Try this

.box{
    display:flex
}
Atif Saleem
  • 126
  • 1
  • 4
  • 1
    While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: https://stackoverflow.com/help/how-to-answer . Good luck – nima Oct 12 '21 at 13:56