0

I'm facing some problem in my css project. I tried to put an image in a div and somehow it puts a white-space below the image.

enter image description here

here is my html code:

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

#top {
  border: solid;
}

#page-top {
  border: solid;
  width: 1028px;
  background: yellow;
  margin: 0 auto;
}

#page-top img {
  width: 30%;
  border: solid;
  display: inline-block;
}
<div id="top">
  <div id="page-top">
    <img src="https://i.imgur.com/7nqdfTK.png">

  </div>
</div>
j08691
  • 204,283
  • 31
  • 260
  • 272
Ron Rofe
  • 738
  • 1
  • 9
  • 25

1 Answers1

1

The default vertical alignment on inline elements is baseline which reserves space for descender text elements. Fix that by setting the vertical align property to top or middle.

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

#top {
  border: solid;
}

#page-top {
  border: solid;
  width: 1028px;
  background: yellow;
  margin: 0 auto;
}

#page-top img {
  width: 30%;
  border: solid;
  display: inline-block;
  vertical-align: middle;
}
<div id="top">
  <div id="page-top">
    <img src="https://i.imgur.com/7nqdfTK.png">

  </div>
</div>
j08691
  • 204,283
  • 31
  • 260
  • 272