Achieving specific column ratios in Bootstrap can be challenging with CSS alone, but there is a workaround using <svg>
elements.
To maintain the ratio of columns, you can place an empty <svg>
inside each column and use the bootstrap class invisible
to hide it from view. Position your content within the column using position: absolute
.
For example, for a 3:2 ratio, set the viewBox
attribute to "0 0 3 2". Adjust the viewBox values accordingly for different column sizes like col-3
and col-6
to maintain the desired ratio.
Keep in mind that in a Bootstrap layout, columns are by default stretched to equal sizes, so adjusting the viewBox values is necessary to maintain the specified ratios.
Feel free to check out the demo below for a visual representation:
/*DEMO*/body{padding:3rem}
.content{
position:absolute;
top:0;
right:0;
bottom:0;
left:0;
overflow:hidden;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<div class="row border">
<div class="col-3 border border-primary">
<svg class="invisible" viewBox="0 0 1 1"></svg>
<div class="content">Lorem Ipsum</div>
</div>
<div class="col-3 border border-danger">
<svg class="invisible" viewBox="0 0 1 1"></svg>
<div class="content">Lorem Ipsum</div>
</div>
<div class="col-6 border border-success">
<svg class="invisible" viewBox="0 0 2 1"></svg>
<div class="content">Lorem Ipsum</div>
</div>
</div>