Tips for preventing divs from sliding to the next row when adding margin in Bootstrap

{% for plant in plants %}
    {% if forloop.counter0|divisibleby:3 %}
        <div class="row row-cols-3">
    {% endif %}
    {% include 'included/_plant_cell.html' %}
    {% if forloop.counter|divisibleby:3 %}
        </div>
    {% endif %}
{% endfor %}

_plant_cell.html:

<div class="plant-cell card col-md-4 m-1">
   <div class="card-body">
      <div class="card-text">
        {{ plant.name }}
      </div>
   </div>
</div>

the issue arises when the code generates rows with only two cards each, and the third one is pushed to the next line (removing margin m-1 fixes this), leading to a pattern of two cards per row followed by one. The expectation is to have three cards in each row.

I hope to resolve this layout issue soon.

Answer №1

_plant_cell.html:

<div class="col-md-4 p-1">
   <div class="card plant-cell">
      <div class="card-body">
          <div class="card-text">
             {{ plant.name }}
          </div>
      </div>
   </div>
</div>

The margin was adjusted to padding using the p-1 class, and I also separated the card plant-cell from the column by adding a subsidiary div. This modification worked well and produced the expected results, making the structure more normalized.

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

Tips on updating the default checkbox dynamically based on the current checkbox using JavaScript

Seeking to enhance the design of a Perl-generated form with custom CSS effects, rather than relying on the default Perl form. Despite successful functionality, encountering an issue where radio button focus reverts to default selection (Date) after submitt ...

Stop menu items from shifting when focused

I've developed a mobile hamburger menu and attempted to adjust the padding to create space between the text and the borders. Here's the HTML: #menu-solutions:hover .menu-item-text, #menu-solutions:focus .menu-item-text, #menu-solutions:ac ...

Backdrop dimming the Material UI Modal

My modal is designed to display the status of a transaction on my website, but I'm facing an issue where the backdrop dimming effect is being applied over the modal. Instead of appearing white as intended, the modal ends up having a dark gray tint. I ...

Altering the input field's content in response to a button click through JavaScript's addEventListener function

I am struggling to get the input text from a form field to change when a button is clicked using JavaScript. I can't seem to figure out why it isn't working correctly. Any assistance would be greatly appreciated. <!doctype html> & ...

Associating data with controller upon click event

My application displays a tab full of objects for the user to choose from by clicking on any line. Once they make their selection, I need to send specific data related to that object to the server. This is what the interface looks like: https://i.sstatic ...

Upgrading to Bootstrap 5 and customizing the collapse button text upon click

I've spent a lot of time searching for a solution to my problem, but all the advice I found is for bootstrap 3 and 4, not version 5. Below is the code I am currently using: <div class="p-3">9 Members Online <a class="p-1 btn ...

Python framework, Django encountering issue connecting to MySQL database

Initially, I was able to successfully connect MySQL in .py using the following code: import pymysql db = pymysql.connect(host='localhost',user='root',passwd='admin',port=3306) cursor = db.cursor() cursor.execute("SELECT VERSI ...

Scroll automatically to the following div after a brief break

On my website, the title of each page fills the entire screen before the content appears when you scroll down. I am interested in adding a smooth automatic scroll feature that will transition to the next section after about half a second on the initial "ti ...

Adding a sibling inline can be accomplished by simply using the "+"

$("#sibling").prepend("#sibling2") <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="sibling">First sibling</div> <div>Another component</div> <div id="sibling2">Seco ...

An issue in D3.js where the chart bars are not properly synced with the x-axis labels

Currently delving into the world of d3.js for the first time. In our project, we needed to adjust the width of each bar from .attr('width', xScale.rangeBand()) line 46 to .attr('width', '10') line 50 After making this cha ...

Getting a jquery lightbox up and running

After experimenting with three different jquery plugins in an attempt to create a lightbox that appears when clicking on a link containing an image, I am currently testing out this one: . Despite adding the plugin source in the head and ensuring that the l ...

What is the best way to make a flex box smoothly appear on the

Is there a way to make a flex box hidden until it fades in without losing its flexibility? I used to use 'display: 0;' and then apply jQuery .fadeIn(). However, setting display to 0 causes the flex properties of the box to disappear when fading i ...

Code Wizard

I am currently working on a project to develop an HTML editor. How it Needs to Function Elements Inside: Text Area - Used for typing HTML as text Iframe - Displays the typed HTML as real [renders string HTML to UI] Various Buttons Functionality: When ...

The hover selector in Material UI and React is not functioning as expected

My code is experiencing an issue where the hover selector does not appear to be working. Although all other styling aspects function correctly, the hover effect is not visible. import React from "react"; import Paper from '@material-ui/core/Paper&apo ...

Ways to stop Bootstrap collapse from displaying depending on a certain condition in bs5 framework

I've been struggling to figure out how to prevent a collapsible panel from opening or showing if a specific value is null. Despite multiple attempts, I haven't had any success. HTML <a href="#" data-bs-toggle="collapse" da ...

Printing Multiple Pages Using JavaScript and Cascading Style Sheets

Encountering difficulties displaying page numbers when printing multiple multipage reports Here is the provided HTML Format : <style type="text/css> body { counter-reset: report 1 page 0; } td.footer:after { counter-increment: page; content ...

JQuery ajax fails to trigger the success function

Upon using an ajax request to insert data into the database, I encountered an issue where the button message did not update after the submission was successful. Initially, I set the button text to Please wait... upon click, and intended to change it to Don ...

During the initial cycle, the CSS keyframes animation may experience glitches, but it will run smoothly in subsequent cycles

Seeking advice on troubleshooting a CSS keyframes animation issue. I have created an animation with 5 frames where the background image fades and transitions to the next image smoothly in all cycles, except for the first cycle where it glitches before each ...

Issue with custom function not being triggered by datepicker onSelect in Internet Explorer with JQuery

I have a datepicker set up like this: $("#startDate").datepicker({ onSelect: changeDate }); This is used with the following input field: <input type="text" id="startDate" value="" class="dateField"/> This setup works well in Chrome, but encou ...

Why does my <p> element in Bootstrap continue to elongate and push everything below it down when I minimize the window?

I've got a standard bootstrap layout set up. <div classs="row-fluid"> <div class="span12" style="background:black; padding:25px 0px;">content content</div> </div> <div class="span4 offset2"> <p>blah blah bl ...