-1

please take a look at this superduper simple pen, maybe someone can tell me where the space in the div under the image is coming from?

HTML

<div class="parent">
    <img src="url">
</div>

CSS

.parent {
    display: inline-block;
    background-color: indianred;
    padding: 0;
    margin: 0;

    img {
        padding-bottom: 0;
        margin-bottom: 0;
    }
}

https://codepen.io/hergi/pen/MQLQRd

thanks in advance, this sh/t is driving me crazy right now :'/

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
SHRX
  • 559
  • 1
  • 6
  • 17

3 Answers3

3

It is because <img> is an display: inline-block element. You can read https://css-tricks.com/fighting-the-space-between-inline-block-elements to understand it.

For short term, you can add

  1. display: block to .parent img
  2. or add font-size: 0 to .parent to fix it.

.parent {
  display: inline-block;
  position: relative;
  background-color: indianred;
  padding: 0;
  margin: 0;
  width: 500px;
  height: 350px;
}

.parent img {
  display: block;
  width: 100%;
  height: 100%;
  padding-bottom: 0;
  margin-bottom: 0;
  position: relative;
}

.hover-border {    
  box-sizing: border-box;
  transition: ease all .3s;
  border: 0 solid rgba(0,0,0,.3);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  &:hover
}
<div class="parent">
  <img src="https://echtlieb.de/themes/Frontend/Echtlieb/frontend/_public/src/img/produkteigenschaften/frauen/doerte/stoff/stoff-sweat_(grau_meliert).jpg" />
  <div class="hover-border">
    
  </div>
</div>
w3debugger
  • 2,097
  • 19
  • 23
1

Just add 'display: block;' to the image. No need to provide height and width to the parent div.

.parent {
    display: inline-block;
    background-color: indianred;
    padding: 0;
    margin: 0;
}

.parent img {
  display: block;
  padding-bottom: 0;
  margin-bottom: 0;
}
<div class="parent">
  <img src="https://echtlieb.de/themes/Frontend/Echtlieb/frontend/_public/src/img/produkteigenschaften/frauen/doerte/stoff/stoff-sweat_(grau_meliert).jpg" />
 
</div>
Ishwar Patil
  • 1,671
  • 3
  • 11
  • 19
0

Just add margin:0px to body tag, by default it takes some margin. check updated snippet below..

.parent {
  display: inline-block;
  background-color: indianred;
  padding: 0;
  margin: 0;
}
.parent img {
  padding-bottom: 0;
  margin-bottom: 0;
}

body {
  margin: 0px;
}
<div class="parent">
    <img src="https://echtlieb.de/themes/Frontend/Echtlieb/frontend/_public/src/img/produkteigenschaften/frauen/doerte/stoff/stoff-sweat_(grau_meliert).jpg" />
</div>
Super User
  • 9,448
  • 3
  • 31
  • 47