How to Fix Gaps in Bootstrap Stacked Rows?

Barbara Streisand
Release: 2024-11-06 06:17:02
Original
989 people have browsed it

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

`

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

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!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!