I want to build a grid with bootstap or flex-box which should look like this:
Unfortunately my attempt with the bootstrap grid isn't working as excpeted. I want that the amount numbers(11, 2) are aligned right and have the same div-box with. In my expectation the div with the number 2 should have the same width as the div with the number 11, means the width of these div-boxes should be based on the bigger one(11). Giving these two divs a static col width is not what I want.
HTML:
<h6 class="py-2">my attempt</h6>
<div class="row text-right">
<div class="col col-md-auto width-should-be-equal">11</div>
<div class="col col-md-auto">*</div>
<div class="col col-md-auto">50$</div>
<div class="col col-md-auto text-center">=</div>
<div class="col col-md-auto">550$</div>
</div>
<div class="row text-right">
<div class="col col-md-auto width-should-be-equal"> 2</div>
<div class="col col-md-auto">*</div>
<div class="col col-md-auto">500$</div>
<div class="col col-md-auto text-center">=</div>
<div class="col col-md-auto">1000$</div>
</div>
<h6 class="py-2">not the goal</h6>
<div class="row text-right">
<div class="col col-md-2 width-should-be-equal">11 </div>
<div class="col col-md-auto">*</div>
<div class="col col-md-auto">50$</div>
<div class="col col-md-auto text-center">=</div>
<div class="col col-md-auto">550$ </div>
</div>
<div class="row text-right">
<div class="col col-md-2 width-should-be-equal">2</div>
<div class="col col-md-auto">*</div>
<div class="col col-md-auto">500$</div>
<div class="col col-md-auto text-center">=</div>
<div class="col col-md-auto">1000$</div>
</div>
CSS:
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
padding: 10px;
}
.width-should-be-equal {
border: 1px solid blue;
}
Thanks for the help!
As explained here there's no flexbox (Bootstrap grid) solution for "fit to width of widest".
IMO, the closest workaround is to use the
display:table-cell
. You can still use the grid row/col and override with table-cell only on md and larger (d-md-table-row
andd-md-table-cell
)...https://codeply.com/p/qwyIJi2PDD