2

Why is the picture element bigger than the image element? (The red line at the bottom of the sample) - chrome 88. How can I prevent that?

picture{
  background-color: red;
}

img{
  width:100%;
  height: auto;
}
<picture>
  <source srcset="https://i.stack.imgur.com/WeyM8.jpg" media="all">
  <img src="">
</picture>
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Jan VeselĂ˝
  • 1,009
  • 12
  • 23

1 Answers1

1

Because as an inline-element, the image is vertically aligned at the baseline, which leaves some space below it. Just add display: block to the image to avoid that.

picture{
  background-color: red;
}

img{
  width:100%;
  height: auto;
  display: block;
}
<picture>
  <source srcset="https://i.stack.imgur.com/WeyM8.jpg" media="all">
  <img src="">
</picture>
Johannes
  • 59,058
  • 16
  • 59
  • 114