I have an two <image />
s and a <p/>
, each wrapped in a <span />
which are again childs of a <div />
. Both images have different dimensions. I need them to always take half of the available width (which works) and then scale them up to 100% of the available height. The latter does not work.
.container {
display: flex;
flex-direction: row;
width: 100%;
column-gap: 10px;
margin-top: 10px;
margin-bottom: 10px;
}
.image-caption-wrapper {
width: 50%;
height: 100%;
}
.image {
width: 100%;
object-fit: cover;
height: 100%;
}
p {
margin: 0;
}
<div>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
<div class="container">
<span class="image-caption-wrapper">
<img class="image" src="https://dummyimage.com/800x200/000/fff"/>
<p>Some Image Caption</p>
</span>
<span class="image-caption-wrapper">
<img class="image" src="https://dummyimage.com/600x400/000/fff"/>
<p>Some Other Image Caption</p>
</span>
</div>
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>
</div>
Why is the 800 x 200
image not taking all the available height, eventhough the height of it is set to 100%?
2
Answers
Hello there,
800 x 200
image not taking all the available height, eventhough the height of it is set to100%
?". So let me explain how you can rectify that problem.flex
layout, but if you want to span the both image elements as you said then you need to usegrid
layoutwidth: 100%
, becausediv
is a block level element so it automatically occupies100%
ofwidth
by default.margin
of50px
for both top and bottom along with changing the width of.image-caption-wrapper
to100%
so that our both images will occupy entire spaceI hope you find this feedback helpful !
you need to give height to main block (.container) , because children blocks
cant understand what 100% they need to fill .