0

I have a <div> containing child <img> element:

<div class="wrapperdiv">
  <img src="blob" class="myimg">
</div>

Now, I want the <div> to have the same height as <img>.

More elaborately, my goal is to have div with img inside to have exactly the same position as if there was only img without wrapper div!

I've tried setting height: auto to the <div>, but while it sets the height to roughly same as <img>, it is larger by 1 pixel, and I'd like them to absolutely equal.

Justin Trevein
  • 1,496
  • 3
  • 12
  • 16

2 Answers2

2

set css :

.myimg { display: block ;}

and

.wrapperdiv { height: unset;}
Dinshaw Raje
  • 933
  • 1
  • 12
  • 33
2

@Justin Trevein, I have prepared one working demo on the basis of comment provided by @fcalderan. I hope this will be helpful.

This DEMO is related to show only Height, and not a width.

.wrapperdiv {
  background-color: green;
}

.wrapperdiv img {
  display: block;
}
<div class="wrapperdiv">
  <img src="https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823_960_720.jpg" class="myimg"/>
</div>

Thanks, Jignesh Raval

Jignesh Raval
  • 587
  • 7
  • 15