I'm currently utilizing Bootstrap 5 in an attempt to design a simplistic layout consisting of an MxN grid of cells, each of equal size. My goal is to have this grid fill the entire viewport without any scrollbars appearing in either direction. However, I am encountering difficulties with the scrollbars.
Various combinations of height and max-height on different div elements have been attempted. While this helped prevent the container div from becoming too tall, the rows end up overflowing vertically. Ideally, I would like everything to shrink down to eliminate the scrollbars, even if it means making the columns narrower. While I prefer using bootstrap, it's not mandatory for this task.
The code snippet below represents where I am at the moment. It appears to be approximately 20% taller than the viewport:
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="284a47475c5b5c5a4958681d061a061b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row p-0">
<div class="col p-0 border">
<span class="ratio ratio-16x9 d-flex align-items-center justify-content-center">
Cell
</span>
</div>
<div class="col p-0 border">
<span class="ratio ratio-16x9 d-flex align-items-center justify-content-center">
Cell
</span>
</div>
</div>
<div class="row p-0">
<div class="col p-0 border">
<span class="ratio ratio-16x9 d-flex align-items-center justify-content-center">
Cell
</span>
</div>
<div class="col p-0 border">
<span class="ratio ratio-16x9 d-flex align-items-center justify-content-center">
Cell
</span>
</div>
</div>
</div>
Edit 1:
It seems that the issue lies with the aspect-ratio property. The current behavior fills the width even if it results in a larger height than desired for the cell.
Below is an updated example without the ratios. The rendering and responsiveness are now correct:
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b5b8b8a3a4a3a5b6a797e2f9e5f9e4">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid d-flex h-100 mh-100 vh-100 flex-column">
<div class="row p-0 flex-grow-1">
<div class="col p-0 border d-flex align-items-center justify-content-center">
<div>
Cell
</div>
</div>
<div class="col p-0 border d-flex align-items-center justify-content-center">
<div>
Cell
</div>
</div>
</div>
<div class="row p-0 flex-grow-1">
<div class="col p-0 border d-flex align-items-center justify-content-center">
<div>
Cell
</div>
</div>
<div class="col p-0 border d-flex align-items-center justify-content-center">
<div>
Cell
</div>
</div>
</div>
</div>
The main objective is to ensure that the cell divs always maintain a 16/9 aspect ratio without exceeding the parent div's dimensions while being centrally aligned both horizontally and vertically within the parent. In essence, the cell divs need to expand until either their height or width reaches the parent div, then stop expanding. Conversely, the current behavior allows the width to reach the parent's width first, even if the height extends beyond the parent's limits.
Furthermore, it should be noted that the number of rows/columns is dynamic, which might impact the solution since sizing cannot be hardcoded relative to the number of rows and columns.
To provide context, the end goal is to present a grid of videos on a single screen without requiring the user to scroll.
Edit 2:
Just to offer more clarity, here are the expectations for the solution:
- Eliminate all scrollbars completely, as users may not be able to scroll in certain situations.
- The solution must accommodate layouts with varying numbers of rows and columns while ensuring content remains easily visible.
- Each cell will contain video content.
- All videos must adhere to the same aspect ratio.
- Since cell dimensions may not match video aspect ratios, videos should be centered in both directions within the cell.
- Responsive resizing based on browser window changes must be supported.
- While bootstrap or CSS solutions are preferred, other options will be considered if necessary.