Getting rid of the excess space at the bottom of a Bootstrap card - tips and tricks!

I encountered an issue while developing a blog app. The problem is that instead of resizing to fit the size of the card, the content is occupying the entire column space.

https://i.sstatic.net/CGRig.png

Here's the code snippet (Jinja2)

{% extends "base.html" %}
{% block title %}
Blogs - DevExplorer
{% endblock title %}

{% block content %}
<div class="container">
    <div class="row no-gutters">
        <div class="text-center">
            <a href="{{ url_for('new_post') }}">
                <button class="btn btn-primary btn-primary btn-lg rainbow-button">Post A New Blog</button>
            </a>

            <br><br><br>
        </div>

        <!-- Displaying the posts, if the database if empty telling the user to post a post -->
        {% if posts.items != [] %}
            {% for i in posts.items %}
                <!-- Displaying the posts if exists -->
                {% if i.thumbnail %}
                <a href="{{ url_for('post_detail', primary_key=i.id) }}" class="col-auto" style="text-decoration: none; color: white;">
                    <div class="col-auto">
                        <div class="card cards" style="box-shadow: 1px 1px 30px black; border: none; width: 612px;">
                            <div class="card-body" style="margin: 0; padding: 0;">
                                <img src="{{ url_for('static', filename='profile_pics/' ~ i.author.profile_picture) }}" alt="DP" width="32"
                                    height="32">&ensp;{{ i.author.username }}
                            </div>

                            <br>

                            <span class="text-muted" style="margin-bottom: 10px;">Posted On: {{ i.date_posted.date() }}</span>
                            <img src="{{ i.thumbnail }}" alt="Image Support" style="border-radius: 25px;">

                            <br>

                            <h5 class="card-title" style="font-weight: 600;">
                                {{ i.title }}
                            </h5>
                        </div>
                    </div>
                </a>
                {% else %}
                <a href="{{ url_for('post_detail', primary_key=i.id) }}" class="col-auto" style="text-decoration: none; color: white;">
                    <div class="col-auto">
                        <div class="card cards" style="box-shadow: 1px 1px 30px black; border: none; width: 612px;">
                            <div class="card-body" style="margin: 0; padding: 0;">
                                <img src="{{ url_for('static', filename='profile_pics/' ~ i.author.profile_picture) }}" alt="DP"
                                    width="32" height="32">&ensp;{{ i.author.username }}
                            </div>
                
                            <br>
                
                            <span class="text-muted" style="margin-bottom: 10px;">Posted On: {{ i.date_posted.date() }}</span>
                
                            <br>
                
                            <h5 class="card-title" style="font-weight: 600;">
                                {{ i.title }}
                            </h5>

                            <p class="elipsis" style="height: 17rem;">
                                {{ i.content }}
                            </p>
                        </div>
                    </div>
                </a>
                {% endif %}
            {% endfor %}
        {% else %}
            <!-- Messaging the user that no posts exists -->
            <h1 style="font-weight: bolder; text-align: center;">No Posts Yet! Be the first to post one!</h1>
        {% endif %}
    </div>

    <!-- Pagination -->
    {% for page_num in posts.iter_pages(left_edge=1, right_edge=1, left_current=1, right_current=2) %}
        {% if page_num %}
            {% if posts.page == page_num %}
                <a class="btn btn-info" style="margin: 5px;" href="{{ url_for('list_posts', page=page_num) }}">{{ page_num }}</a>
            {% else %}
                <a class="btn btn-outline-info" style="margin: 5px;" href="{{ url_for('list_posts', page=page_num) }}">{{ page_num }}</a>
            {% endif %}

        {% else %}
            ...
        {% endif %}
    {% endfor %}

</div>
<br><br>

{% endblock content %}

I attempted to use col-auto to resolve the issue, but it still persists and distorts the page layout. Any assistance would be highly appreciated!

Answer №1

What's happening here is that the card is adjusting its height based on the content inside it. If you want the cards to have different heights on the same axis, you can use a library called Masonry. This will help you achieve the desired layout.

To implement Masonry, include this JavaScript file in your document:

<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>

Additionally, add

data-masonry='{"percentPosition": true }'
to the .row wrapper.

Check out the code snippet in action below:

<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
<link href="https://getbootstrap.com/docs/5.0/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row" data-masonry="{"percentPosition": true }" style="position: relative; height: 1953.6px;">
    <!-- Cards Go Here -->
  </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

CSS - Layering new DIVs over existing DIVs

My goal is to implement "vertical-align: bottom;" in order for the DIVs to align from the bottom of the wrapper/parent DIV to the top. However, I am facing an issue where I want the first DIVs to be displayed at the bottom, rather than at the default top p ...

What is the best way to make a CSS class appear in my javascript using the method I have been using before?

I am facing an issue in making this code work properly. It functions correctly for my caption element as there is only one caption tag in my HTML. However, the same code does not work for my TR element since it requires a for loop to iterate through multip ...

Syntax error detected: Unexpected T_ELSEIF statement

I have been attempting some basic coding on codeacademy and struggling with an issue for the past hour. What could be causing this error to display: "Parse error: syntax error, unexpected T_ELSEIF on line 12 " <html> <head> <title&g ...

Utilizing CSS or JavaScript to define the input type

I currently have a group of checkboxes displayed on a webpage within a DIV labeled OPTIONS, shown below: <div id="options"> <input type="checkbox"..... > <input type="checkbox"..... > <input type="checkbox"..... > <input t ...

The Wordpress block template is inhibiting Bootstrap from managing responsiveness

In the process of creating a custom WordPress block theme, I encountered a styling dilemma. While I wanted to maintain WordPress styling for its built-in blocks, I aimed to have Bootstrap exclusively style the blocks created within my theme. With Bootstrap ...

Objects and strings cannot be inserted into a JavaScript array

For hours, I've been attempting to troubleshoot this code. Currently, it successfully finds the number of anchors, and I have an array that is of undetermined size. Within the for loop, it retrieves the anchor and extracts the .href. I've confirm ...

Master the art of displaying complete text when zooming in and elegantly truncating it when zooming out

I am currently working on a data visualization project using d3.js. The tree chart that I have created is functioning well, but I would like the text to react dynamically when zooming in and out. You can find the code for my project on this JSFiddle page. ...

Utilizing jQuery/Ajax to send an ID parameter to a PHP script

This code is where the user interacts. <html> <head> <title></title> <script src="jquery-1.9.1.js"></script> <script src="jquery.form.js"></script> </head> <body> <?php include 'con ...

Storing the value of the current vertical scroll position in a variable using jQuery

I'm currently dealing with a challenge that involves using the value of (window).scrollTop() as a crucial variable in my project. What I aim to accomplish is to retrieve and utilize the specific scroll value at a particular moment within an if stateme ...

Need help triggering Ajax code upon clicking a link?

Can someone help me find the issue with my script? Below is the code snippet: <script> $(".icross").click(function(e){ e.preventDefault(); var obj = $(this); $.ajax({ type: "GET", url: "supprimer.php", data: 'id=&a ...

The issue I am facing is that the MDCSelect:change event does not seem to be functioning properly

Is there a way to get MDCSelect:change to work properly before appending all options? If I put MDCSelect:change after the list append, it works but the UI doesn't look right. Question: How can I make MDCSelect:change work without affecting the UI ap ...

Creating a fixed column in an Angular Material Table for enhanced user experience

Has anyone found a method to implement a sticky first column in Angular Material using CSS? Check out the editable Stackblitz code here. I attempted to modify this approach from https://jsfiddle.net/zinoui/BmLpV/, but encountered issues where the first c ...

Unable to perform the 'setSelectionRange' function on the 'HTMLInputElement' due to the input element's type being 'number', which does not allow selection

My attempt to enable text selection in an input box upon user click by using the code snippet below was unsuccessful: <input type="number" onclick="this.setSelectionRange(0, this.value.length)" name="quantity" /> Instead of achieving the desired ef ...

Links have a longer transition delay compared to the content

In a unique JavaScript function I've developed, the my-content-section-visible class is removed and replaced with my-content-section-hidden. This change is being made to hide a particular div using a smooth transition effect. The transition itself is ...

Achieving a seamless integration of a navbar and video in Bootstrap 5.3: tips and tricks

I'm updating a website design using Bootstrap and I want to create a navbar with a video playing in the background. To ensure that the navbar stays fixed at the top while scrolling, I made it sticky. After testing various methods, I managed to posit ...

Animating the maximum height causes a delay in the performance of other elements

Attempting to adjust the maximum height of a ul. When the max-height property changes (via toggling a class), the height shifts immediately, while the items below the ul maintain the animated height as expected. var expander = $('.skill-expand&apos ...

Creating a dual-row HTML table heading

Looking to create a table with a two-row header - the first row containing a search input box and the second row containing column names. Here's what I have so far: <thead> <tr class="bg-primary"> <th colspan="5"> ...

Is it possible to restrict contenteditable elements to only accept numbers?

Is there a way to restrict contenteditable elements such that only numerical values can be entered? I attempted to use the following code snippet: onkeypress='return event.charCode >= 48 && event.charCode <= 57' However, despite a ...

Tips for adjusting the color of boxes within a grid

I've built a grid containing multiple boxes, each identified with an id of box + i. However, I'm encountering difficulties when attempting to implement an on-click function to change the color of each box. Below is the code snippet in question: f ...

Updating the value of an Angular select on change is not being reflected

If the select element is changed, the value should be set to something different from what was selected. There's a feature in place that only allows 4 item types to be selected at a time; if more than 4 are chosen, the value reverts back to its origin ...