Home > Web Front-end > CSS Tutorial > How to Avoid Empty Vertical Space Between Columns in Bootstrap 4?

How to Avoid Empty Vertical Space Between Columns in Bootstrap 4?

Susan Sarandon
Release: 2024-11-14 13:06:02
Original
171 people have browsed it

How to Avoid Empty Vertical Space Between Columns in Bootstrap 4?

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:

  • Column A: Description (Tall)
  • Column B: Sidebar (Short)
  • Column C: Comments (Tall)

Flexbox aligns columns vertically, resulting in:

------------------  ---------
|                  ||         |
|                  ||         |
------------------ |         |
------------------ |         |
|                  ||         |
------------------  ---------
Copy after login

But we desire:

------------------  ---------
|                  |
 ------------------  
|                  |
 ------------------ |         |
|                  ||         |
 -------------------  ---------
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template