If I understand it correctly, the col-auto
classes in Bootstrap is supposed to only use the natural width of the content. When I use col-lg-auto
in the code below, the width becomes larger than the content.
I've created this Codepen that demonstrates the issue.
<div class="row">
<div class="col">
<div class="row">
<div class="col-12 col-sm-6 col-lg-4">Col</div>
<div class="col-12 col-sm-6 col-lg-4">Col</div>
<div class="col-12 col-sm-6 col-lg-4">Col</div>
<div class="col-12 col-sm-6 col-lg-4">Col</div>
<div class="col-12 col-sm-6 col-lg-4">Col</div>
<div class="col-12 col-sm-6 col-lg-4">Col</div>
<div class="col-12 col-sm-6 col-lg-4">Col</div>
<div class="col-12 col-sm-6 col-lg-4">Col</div>
<div class="col-12 col-sm-6 col-lg-4">Col</div>
</div>
</div>
<!-- Replace col-lg-auto with col-lg and add class flex-grow-0 -->
<div class="col-12 col-lg-auto">
<div class="row">
<div class="col-6 col-lg-12">Content</div>
<div class="col-6 col-lg-12">Content</div>
<div class="col-6 col-lg-12">Content</div>
<div class="col-6 col-lg-12">Content</div>
<div class="col-6 col-lg-12">Content</div>
<div class="col-6 col-lg-12">Content</div>
</div>
</div>
</div>
If the row
inside col-lg-auto
only has one column child, then it works as expected. I'm also able to achieve the layout I want if i replace the class col-lg-auto
with the classes col-lg
and flex-grow-0
.
Can someone please explain why the width of col-lg-auto
does become larger than the content width in this scenario? Can i not use a row with multiple columns inside a column that has the class col-auto
?