I have set up my design as follows:
I've created a responsive image box that functions as a square using a pseudo element :after
with the CSS property padding-bottom: 100%;
The challenge I'm facing:
I'm attempting to place a sidebar next to my main image box, which may contain multiple smaller thumbnail images. The issue is that in Bootstrap's default behavior, the smaller boxes adjust their sizes to match the larger one. What I want is for the sidebar to always be the same height as the main image box. If the sidebar content exceeds this height, it should scroll vertically instead.
I tried enclosing the sidebar within a wrapper div but the size of the sidebar still grows according to its content.
My question is:
How can I ensure that the sidebar only takes on the maximum height of the square box placed beside it?
.row {
margin-top: 20px;
}
.row>div {
border: solid 1px #6c757d;
padding: 10px;
}
img {
display: block;
border: 1px solid red;
}
.sidebar>div:not(:last-child) img {
margin-bottom: 10px;
}
.main img {
width: 100%;
height: 100%;
object-fit: cover;
}
.main .wrapper {
border: 1px solid green;
position: relative;
}
.main .wrapper:after {
content: "\00a0";
display: block;
padding-bottom: 100%;
line-height: 0;
}
.main .holder {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 100%;
}
.sidebar-wrapper .sidebar {
height: 100%;
overflow-y: scroll;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" />
<!-- Code continues... (partially omitted for brevity) -->
</div>