How do I get auto-width-columns in Bootstrap like in UIKit?
I need 5 columns with auto width.
In UIKit you get it with <div class="uk-width-1-5">
How do I get auto-width-columns in Bootstrap like in UIKit?
I need 5 columns with auto width.
In UIKit you get it with <div class="uk-width-1-5">
Bootstrap 4+ you can use the col class alone and it will resize to what space is available.
<div class="row">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
</div>
Using class="col"
will automatically make the columns equal in size.
But if you want some column(s) to resize depending on its/there content(s), use something like class="col-auto"
.
Use
class="col-{breakpoint}-auto"
classes to size columns based on the natural width of their content.Reference: https://getbootstrap.com/docs/4.0/layout/grid/#variable-width-content
Bootstrap 5 (update 2023)
Bootstrap 5 still uses a flexbox grid so auto-sizing is still possible using the .col
to .col-auto
classes so that columns take up as much space as needed.
Bootstrap 4
Bootstrap 4 uses a flexbox grid so auto-width columns are achieved using the col
and/or col-auto
classes. The col
class will create equal width columns, while col-auto
columns will shrink to fit the width of their content.
Bootstrap 3 (original answer)
The 5 columns aspect of this question has been answered here. Since Bootstrap has 12 columns, you only use 10 of them with 5 col-*-2 units
http://codeply.com/go/QXiPmtgJUJ
In terms of "auto-width", Bootstrap 4 will have new auto-layout columns that consume the remaining portion of any row, but this is still based on a 12 column grid.