Home > Web Front-end > CSS Tutorial > How to Vertically Align Uneven Height Divs in Bootstrap Rows Using CSS Clearfixes?

How to Vertically Align Uneven Height Divs in Bootstrap Rows Using CSS Clearfixes?

Linda Hamilton
Release: 2024-11-15 22:55:04
Original
728 people have browsed it

How to Vertically Align Uneven Height Divs in Bootstrap Rows Using CSS Clearfixes?

Vertical Alignment of Uneven Height Divs in Bootstrap Using CSS Clearfixes

The goal is to vertically align divs of varying heights within a Bootstrap row without using external plugins like Masonry. Here's a CSS solution:

In the provided HTML structure, each category is represented by a div with the class "menu-category". These divs have different heights due to varying items within each category. To achieve the desired stacking, we can utilize Bootstrap's visibility classes.

Specifically, we can add a "clearfix" class with visibility modifiers to selectively clear the floats in the div layout. For instance, if you want to clear the floats only in medium and large screen sizes, you can use the following code:

<div class="clearfix visible-md visible-lg"></div>
Copy after login

Similarly, to clear floats only in small screen sizes, use:

<div class="clearfix visible-sm"></div>
Copy after login

By adding these clearing divs to appropriate places in the HTML structure, you can prevent the floating divs from wrapping to the next line, forcing them to stack vertically.

Example:

Copy after login

With this approach, the div heights will adjust dynamically based on the content, ensuring they stack neatly within the row container.

The above is the detailed content of How to Vertically Align Uneven Height Divs in Bootstrap Rows Using CSS Clearfixes?. 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