Empty Vertical Space Between Columns in Bootstrap 4
Bootstrap 4 introduces flexbox, resulting in columns sharing the same height as the tallest column. This creates an undesirable empty space between columns in certain scenarios.
Flexbox Alignment and Empty Space
Consider this:
Flexbox aligns columns vertically, resulting in:
------------------ --------- | || | | || | ------------------ | | ------------------ | | | || | ------------------ ---------
But we desire:
------------------ --------- | | ------------------ | | ------------------ | | | || | ------------------- ---------
Floats as a Workaround
Bootstrap 3 used floats, which allows columns to float and take up only the space they need. To achieve this in Bootstrap 4:
<div>
The d-lg-block class forces display:block on the row, allowing columns to float on large screens.
Nesting and Order Preservation
Nesting columns as follows may seem like a solution:
<div>
However, this compromises column order. In the above example, the sidebar will appear last on small screens due to the automatic layout of nested rows.
The above is the detailed content of How to Avoid Empty Vertical Space Between Columns in Bootstrap 4?. For more information, please follow other related articles on the PHP Chinese website!