Bootstrap is an awesome toolkit when it comes to build responsive web pages that work across different browsers with little effort. Its grid system is very well crafted, but it doesn’t allow to have a number of same-width columns per row which is not a divisor of 12.
Note: I know one could use the CSS grid now, but this article is about Bootstrap.
It some cases, one wants/needs to fit, for instance, 5 equal-width columns in a row, and to have them take all the available space. Good news, this is possible: you just need a few custom CSS rules.
Let’s stick to the example of 5 columns per row. We need a
col-? rule for that.
12 / 5 = 2.4, so it’s a column
which is 2.4 columns wide: let’s call it
Each column should eat
20% of the available space (
100 / 5 = 20): that’s easy.
The CSS code which comes out is this:
As of my latest tests, this solution works fine with Boostrap 4.1.1.