Home >Web Front-end >CSS Tutorial >How to Fix Gaps in Bootstrap Stacked Rows?

How to Fix Gaps in Bootstrap Stacked Rows?

Barbara Streisand
Barbara StreisandOriginal
2024-11-06 06:17:021081browse

How to Fix Gaps in Bootstrap Stacked Rows?

Gap in Bootstrap Stacked Rows?

When creating a Bootstrap grid that stacks from larger to smaller screen sizes, it's common to encounter gaps when items with long content disrupt the stacking order. Here are several solutions to address this issue:

1. Set Element Heights:
Assign a fixed height to all elements in your portfolio grid.

2. Use Masonry:
Employ a library like masonry.js that dynamically adjusts element sizes to fit into available spaces.

3. Responsive Class and Clearfix:
As described in Bootstrap's documentation under "Responsive Column Resets," use responsive classes and add a div with the "clearfix" class following each element in the grid to prevent gaps.

4. jQuery Height Adjustment:
Use jQuery to adjust the height of columns dynamically based on the maximum height within the grid.

Example using the Responsive Class and Clearfix Approach:

Add a "clear" class to each element in the grid:

`<div>

<div>

`

Add CSS to handle different breakpoints:

@media (max-width: 767px) {
    .portfolio>.clear:nth-child(6n)::before {
        content: '';
        display: table;
        clear: both;
    }
}
@media (min-width: 768px) and (max-width: 1199px) {
    .portfolio>.clear:nth-child(8n)::before {
        content: '';
        display: table;
        clear: both;
    }
}
@media (min-width: 1200px) {
    .portfolio>.clear:nth-child(12n)::before {  
        content: '';
        display: table;
        clear: both;
    }
}

The above is the detailed content of How to Fix Gaps in Bootstrap Stacked Rows?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:How to Ensure Disabled Select Fields Submit with Forms?Next article:How to Ensure Disabled Select Fields Submit with Forms?

Related articles

See more