Is the Bootstrap 4 dropdown within a card causing column breaks?

Having an issue with using Bootstrap 4, particularly reactstrap but the problem can be recreated in regular Bootstrap, where I am utilizing 'card-columns' to make a grid of cards, each card containing a dropdown menu in the 'card-footer'. The issue arises when there are 4 or more cards as the dropdown appears to break across columns somehow....with its position varying from where Chrome highlights the element, as depicted in this image:

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

If I increase the card count and open the dropdown on some cards, they change positions - seemingly 'jumping around'.

Here is a basic example:

body {
  margin: 10px;
}

.dropdown-menu {
  margin-top: 10px;
  margin-bottom: 10px;
}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">


<div class="container-fluid h-100">
  <div class="mx-4 my-2 row">
    <div class="mx-4 row">
      <div class="card-columns">
        <div class="card border-secondary">
          <div class="card-footer">
            <div class="row">
              <div class="col-md-8">
                <div class="btn-group show">
                  <button class="dropdown-toggle btn btn-outline-secondary">
                   More
                  </button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="card border-secondary">
          <div class="card-footer">
            <div class="row">
              <div class="col-md-8">
                <div class="btn-group show">
                  <button class="dropdown-toggle btn btn-outline-secondary">
                   More
                </button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="card border-secondary">
          <div class="card-footer">
            <div class="row">
              <div class="col-md-8">
                <div class="btn-group show">
                  <button class="dropdown-toggle btn btn-outline-secondary">
                   More
                </button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="card border-secondary">
          <div class="card-footer">
            <div class="row">
              <div class="col-md-8">
                <div class="btn-group show">
                  <button class="dropdown-toggle btn btn-outline-secondary">
                   More
                </button>
                  <div role="menu" class="dropdown-menu show" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 27px, 0px);" data-placement="bottom-start">
                    <button class="dropdown-item">
                      Button 1
                    </button>
                    <button class="dropdown-item">
                      Button 2
                    </button>
                    <button class="dropdown-item">
                      Button 3
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="card border-secondary">
          <div class="card-footer">
            <div class="row">
              <div class="col-md-8">
                <div class="btn-group show">
                  <button class="dropdown-toggle btn btn-outline-secondary">
                   More
                </button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

In this instance, only the last 2 buttons of the menu seem to appear elsewhere than intended - the viewport must be wide enough to display more than 1 column for this issue to manifest.

The problem likely stems from the dropdown extending beyond the cards' boundaries when opened, despite being absolutely positioned.

How can I create such a dropdown without disrupting the card-columns layout?

Answer №1

It appears that the issue stems from the utilization of card-columns. These columns are generated using CSS columns, and any modifications to the content display within them, such as dropdown menus, may result in erratic behavior.

To exemplify this concern, I have crafted a simplified version of your code. In the first iteration, clicking on the dropdown causes the columns to shift unexpectedly. I have included a section of commented-out CSS code that overrides this behavior to demonstrate that the columns are the root cause. If you were to uncomment this block, it will work as intended (utilizing flexbox).

Therefore, instead of relying on card-columns, I recommend utilizing the Bootstrap grid system. While this approach may not replicate the masonry effect precisely, it is preferable to the inconsistent layout you are currently experiencing.

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

Click on the button to insert a new row into the table

Recently I've begun learning Angular. In my project, there is a table and a button. When the button is clicked, a new row identical to the previous one should be added to the table. I have included a link to the StackBlitz demo below. Any guidance on ...

In what way are these fonts being displayed through the utilization of a .js file?

Why are people opting for unique fonts on their browsers using .js files instead of graphics? For example, like typekit? ...

The main React component fails to fully load the index.html file

I am a beginner in the world of reactjs and I have encountered a problem with loading CSS in the head and JS libraries and plugins at the end of the body in my template. Here is how my index.html looks: <!DOCTYPE html> <html lang="en"> <hea ...

Tips on aligning smaller text within a larger CSS structure

Is it possible to align smaller text with larger CSS? Below is the code snippet: <div class="header"> <div class="navbar"> <img src="img/logo.png" alt="" style=""> <font color="white">LOGO</font> ...

Send a MySQL query and an HTTP request to an SMS gateway through JavaScript

I have a scenario where data is being received by my confirm.php file. In this file, I have the following code and currently facing an issue with the javascript part. Any help and suggestions would be greatly appreciated. The objective of my javascript is ...

A div element retains its height even when empty, disregarding the minimum height set to

My goal is to style a div in such a way that its height adjusts based on the text it contains, as long as it stays within the maximum height set. However, I am facing an issue where even if there is no text inside the div, it still retains some height. ...

Getting the value of a checkbox in Bootstrap: a comprehensive guide

I encountered the following snippet of HTML code: <div type="checkbox" id="myCheckbox" name="bootStrap1" class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-animate bootstrap-switch-on"> <div ...

Showing the Y-axis value when hovering over the turning point of a graph

Creating a graph using javascript and canvas, here is the jsfiddle link available: http://jsfiddle.net/ghan_123/n0r796ae/ Would like to display values on hover bubble (turning points) like: Price 2100 on 1-aug Javascript code: var CanvasChart = functi ...

Tips for adjusting the width of text input in a bootstrap table

I have a table with 7 text input fields using Bootstrap 2.3 styles. I want to resize these input fields to take up less width in the table cell, but I haven't been successful. I attempted to use the span1 class, but it didn't shrink them as desi ...

Conceal the choice if its value matches that of another option

My goal is to create a code that will hide an <option> if its value matches the value of the first option (which is retrieved dynamically with PHP). Here's the initial code snippet: <select onChange="this.form.submit()" name="cart[<?php e ...

I am experiencing an issue where the CSS file in the wwwroot directory does not update when I make changes to the code in ASP.NET MVC

Here is a link to my CSS file: Click here for image description This is how the file looks when built (no changes): Click here for image description Occasionally, running "clean-solution" and "build-solution" fixes the issue, but it's not working no ...

Position this menu in the top left corner using HTML and CSS

Is there a way to position the vertical menu completely in the top-left corner without any margin? I've set all margins to 0 but there is still about 2px of space. Any ideas on how to fix this? Thank you in advance! ...

Positioning buttons in a grid using CSS - Tips and tricks

Help needed! Seeking professional advice. I have a few issues that I can't seem to solve on my own. Firstly, regarding the second menu - should I use padding to position it correctly? Secondly, although I managed to make the navigation bar visually s ...

My Bootstrap4 Accordian seems to be dysfunctional. I would appreciate it if someone could take

I'm experiencing an issue with my Bootstrap 4 accordions in a project. The tabs that are closed do not expand when clicked on the webpage, despite using Bootstrap 4 code. Any suggestions on how to solve this problem would be greatly appreciated. ...

Guide on developing a CSS countdown timer

I recently came across an article discussing the creation of a CSS countdown timer. Intrigued by the concept, I decided to give it a try myself. However, my implementation seems flawed and the live demo link provided in the article is not working. Can some ...

Ways to update images without having to reload the page following an ajax request

My current script uploads images to the server and updates the image source in HTML upon completion. However, I am facing an issue with my PHP code renaming the files to predefined names (ext-pix0.png, ext-pix1.png, etc.) during upload. This leads to the p ...

Transitioning the font stack from SCSS to JSS (cssinjs)

We are currently implementing a variety of custom fonts with different weights for various purposes. With our entire stack now using Material UI with JSS theming and styling, we aim to eliminate the remaining .scss files in our folder structure. All the f ...

The CSS modifications are only visible in my browser after I delete the browsing data

After setting up a landing page with simple text in the center of the screen using flex, I encountered an issue. Whenever I made changes to the CSS, they would not reflect in my browser unless I cleared the browsing data (history, cookies, etc). This probl ...

difficulty generating a tooltip

Purpose: My main goal is to implement a tooltip feature where hovering over text triggers the display of a tooltip. To achieve this, I am seeking inspiration from an example on w3schools which can be found at this link. Current Implementation: render() { ...

Tips on preventing jquery ui tooltip from appearing within a child div

Is there a way to include a tooltip only in the parent div and not in its child div? I am currently using jQuery UI tooltip like this: $(function () { $("#parent_div").tooltip(); }); This is how the HTML looks: <div id="parent_div" title="Hello ...