Space below div with image

Asked

Viewed 51 times

0

In HTML and CSS is appearing a white space below the image, see the example, the error is this white space between the image and the black box

.div1{
  width: auto;
  height: auto;
  display: block;
}
.div2{
  width: 100%;
  height: 40px;
  display: block;
  background-color: #000000;
}
<div class="div1">
<img src="https://i.stack.imgur.com/stNlx.jpg">
</div>
<div class="div2"></div>

How to solve?

  • 1

    Wow, you can put a margin-bottom: -4px; to solve initially...

  • you can try this as well by placing this style in the div1... width: 100%; height: 195px; background-image: url(https://i.stack.Imgur.com/stNlx.jpg); background-position: center; background-repeat: no-repeat; background-size: 70% auto;

  • @Robertcezar Insert an image using the tag <img> is completely different to insert it as background of an element. They are not equivalent solutions and therefore one does not replace the other.

  • @Andersoncarloswoss I’m aware friend, just a way in case he wants to explore... just forgot to say he should remove the tag <img> if use.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.