Reputation: 323
I am trying to have a two row hierarchy display for some photos using bootstrap 5. However, rather than staying within the container the images overflow out. I want the container to fill the screen so that it acts as a cover display without the user having to scroll. How can I make them dynamically resize to fit the container?
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container" style="height: 100vh; background-color: yellow;">
<div class="row justify-content-center">
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
</div>
<div class="row">
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
</div>
</div>
The elements are overflowing like this:
I want it to instead scale down the images to look like this:
I tried setting a set height on the elements, but then they take up the whole screen as if the height is not defined relative to the container. Is there some different method I can use to display the images so that they change dynamically?
Upvotes: 1
Views: 1114
Reputation: 1021
The only thing I can think of regarding your issue is the fact you have height: 100vh
set on your container. Remove it.
As you can see here, I added another row and your container scaled just fine;
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container" style="background-color: yellow;">
<div class="row justify-content-center">
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
</div>
<div class="row">
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
</div>
<div class="row">
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
</div>
</div>
However, if you put the height back in, you will see not so fine;
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container" style="height: 100vh; background-color: yellow;">
<div class="row justify-content-center">
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
</div>
<div class="row">
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
</div>
<div class="row">
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
<div class="col col-12 col-md-4">
<img class="w-100 p-5" src="https://via.placeholder.com/1080" style="border-radius: 80px;">
</div>
</div>
</div>
Remember, if you set a height or width of an object it is BOUND to that restriction. If you remove width or height, it's dynamic or based on the object.
Upvotes: 1