"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Stack Divs of Varying Heights in Bootstrap Using CSS?

How to Stack Divs of Varying Heights in Bootstrap Using CSS?

Posted on 2025-03-23
Browse:113

How to Stack Divs of Varying Heights in Bootstrap Using CSS?

Stacking Divs of Varying Heights in Bootstrap Using CSS

In this scenario, the row system of Bootstrap poses a challenge in optimally displaying categories of varying heights. To address this issue without using the masonry plugin, consider the following CSS solution:

  1. Utilize visible classes for responsive stacking:
    Utilize the .visible-sm, .visible-md, and .visible-lg classes in conjunction with clearfix. This ensures that floats are cleared appropriately based on screen size.

  2. Example implementation:
    Below is a simplified demonstration for two categories with different heights:

  3. Additional notes:

    • .visible-sm clears floats for small screens (
    • .visible-md clears floats for medium screens (>768px)
    • .visible-lg clears floats for large screens (>1200px)
    • Adjust the style="height: ...;" attribute to suit your specific category div heights
    • Ensure that the clearfix class is applied outside of the columns to effectively clear the floats
  4. By implementing this technique, you can achieve a responsive stacking of div elements with varying heights within the grid system of Bootstrap. This approach provides a pure CSS solution compatible with Bootstrap, addressing the need for optimal layout visualization.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3