Div splits into two when positioned absolutely

Currently, I am playing around with Bootstrap 4 and have a card nested inside a card-columns:

<div class="card-columns">
   <div class="card">
      <div class="card-block">
         <h4 class="card-title">iPhone 5S</h4>
         <h6 class="card-subtitle text-muted">Rp. 8.999.999</h6>
      </div>
      <img data-src="holder.js/100%x200" alt="100%x200" data-holder-rendered="true" style="height: 200px; width: 100%; display: block;">
      <div class="card-block">
         <p class="card-text">Apple iPhone 5S is the most advanced phone from Apple. Get it at a special price from Shopoza! Enjoy 0% installment
         </p>
         <div class="btn-group open">
            <a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">Add to cart</a>
            <div class="dropdown-menu" style="
               /* min-height: 100%; */
               /* overflow: auto; */
               /* max-height: 100%; */
               /* height: 100%; */
               ">
               <a class="dropdown-item" href="#">Action</a>
               <a class="dropdown-item" href="#">Another action</a>
            </div>
         </div>
         <a href="#" class="btn btn-secondary card-link">Quick checkout</a>
      </div>
      <!-- card block -->
   </div>
   <!-- card -->
</div>

The card-columns itself is within a container that has a row with a single col-sm-12 column.

This is what appears on the screen:

Button menu displayed into half

What seems to be the issue here? The dropdown-menu div class has absolute positioning.

Answer №1

The layout in your example utilizes the .card-column class, which relies on the CSS property column. By default, the column-count within the .card-column layout is set to 3.

Despite the position value of absolute for the .dropdown-menu, there may not be enough space for it to display in the first column due to insufficient height. As a result, it may appear at the top of the next column.

An initial solution could involve increasing the margin-bottom of the .card elements. However, this approach would introduce gaps between columns and create issues when adjusting the column-count for smaller screens or adding more items to the

.dropdown-menu</code.</p>

<p>A more effective resolution is to implement a <code>.card-deck
layout with display: flex. Below is an illustration:

@import url('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css');

.card-deck {
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
}

.card-deck .card {
  flex: 0 1 22.5rem;
  margin: 0 .25rem .50rem;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/js/bootstrap.min.js"></script>

<div class="container">
  <div class="row">
    <div class="card-deck">
      <div class="card">
        <div class="card-block">
          <h4 class="card-title">iPhone 5S</h4>
          <h6 class="card-subtitle text-muted">Rp. 8.999.999</h6>
        </div>
        <img src="http://placehold.it/380x200" class="img-responsive"/>
        <div class="card-block">
          <p class="card-text">Apple iPhone 5S adalah handphone tercanggih dari Apple. Dapatkan
            dengan harga khas dari Shopoza! Nikmati cicilan 0%
          </p>
          <div class="btn-group">
            <a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Add to cart</a>
            <div class="dropdown-menu">
              <a class="dropdown-item" href="#">Action</a>
              <a class="dropdown-item" href="#">Another action</a>
            </div>
          </div>
          <a href="#" class="btn btn-secondary card-link">Quick checkout</a>
        </div>
      </div>
      <!-- additional cards -->
    </div>
  </div>
</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

Table with Typewriter Style CSS Animation

I came across an interesting typewriter effect implementation using CSS in an article on CSS Tricks I decided to play around with it and see if I could apply it to a hero image, which I found an example of on Codepen However, I noticed that the blinking ...

What is the best way to animate my logo using JavaScript so that it scales smoothly just like an image logo

I dedicated a significant amount of time to create a unique and eye-catching logo animation for my website! The logo animation I designed perfectly matches the size of the logo image and can be seamlessly integrated into the site. The issue arises when th ...

Ways to eliminate or conceal solely the play/pause symbol or button from the media player within the video tag

[Please see the screenshot attached, I am looking to remove the play/pause icon that is highlighted] [screenshot] How can I hide or remove only the play/pause button from the media player of a video tag? When I dynamically add the controls attribute using ...

Create stunning HTML emails by incorporating a transparent background color behind images and text

Is there a way to add text on a transparent background layer placed over an image without using the background-image property? In my case, I am working on an HTML Emailer and must utilize the img tag instead. Any suggestions on how to achieve this? < ...

Different width can be set for the Google Maps template specifically for mobile mode by following these steps

Is there a way to adjust the width of a Google Maps template specifically for mobile mode? While it looks perfect on desktop, the map overflows the screen size on mobile. See my code snippet below: @section ('map') <div id="map"></d ...

Moving elements using CSS

Hi, I've been facing this issue with my web development since the start. Whenever I zoom in, the container also moves along. Is there any way to fix this problem? .darkslidecont{ width: 200px; height: 50px; position: relative; bac ...

The tooltip for the Google+ button stopped working

After setting up my Portfolio, I added a Google+ button. However, the page lacks styling and there seems to be an issue with the tooltip causing delays. Can anyone help me identify where the problem lies? ...

Adjust the size of multiple elements upon hovering over one of them

I encountered a puzzling issue, and here is a demonstration of my problem: https://jsfiddle.net/k1y8afst/ <div class="Sample"> <div class="Dummy"> <div class="Books"> <a st ...

Switch the background image of a link within an accordion with a simple click

I'm attempting to create a toggle effect for a background image on a links within an FAQ accordion using javascript. After referencing this jsfiddle example (http://jsfiddle.net/QwELf/), I was able to get things to function. You can view my page in ...

jQuery .attr malfunctioning, retrieving incorrect links

I'm currently in the process of working on this page for a project $(function() { $(".modal-launcher, #modal-background").click(function() { $(".modal-content, #modal-background").toggleClass("active"); $(".vid-1i").attr("src", "l ...

Turn off the Ripple effect on MUI Button and incorporate a personalized touch

I am trying to create a custom click effect for the MUI Button by removing the default ripple effect and implementing my own shadow effect. I have disabled the ripple using disableRipple, but I am facing issues in applying the shadow effect when the user c ...

Numerous links were chosen and multiple div elements were displayed on the screen

Currently, I have a setup where selecting one div will show its content. However, I am looking to enhance this by allowing multiple divs to be displayed simultaneously. For example, if 'Div 1' is selected and shown, I want the content of 'Di ...

Achieving vertical alignment and stretching of subchild within a flexbox element

I am in the process of creating a mobile navigation menu using Flexbox. It will be a vertical menu that occupies 100% of the available height, with the navigation items evenly spaced and taking up the entire height. The structure I am using is ul>li> ...

Employ the Bootstrap "prepend" feature in combination with react-select

When attempting to integrate Bootstrap's input-group-prepend with react-select, a style inconsistency is encountered. React-select does not align perfectly with the current bootstrap/reactstrap styling, causing some elements to not work together as in ...

Expanding the jQuery vertical tab content section to span the entire width of the page

I set up a vertical tab interface following the instructions here, but I'm having trouble with the content area not extending all the way across the page. I've been experimenting with adjusting the CSS by adding width='100%' attributes ...

Is there a way to ensure that the fixed modal remains at the forefront and that its top stays in view even as the user scrolls?

Can you assist me in simplifying this code? import { LoginProps } from '@/layouts/layout.props'; import { Box, Button, Divider, Flex, FormControl, FormLabel, Heading, HStack, IconButton, Input, Link, Stack, Text, } from ...

Can child elements be centered using their pseudo-elements using CSS alone?

Consider the code snippet below: <div class="example-container"> <p class="example">a</p> <p class="example">bbb</p> <p class="example">cc</p> </div> and the cor ...

Creating a multiline centered navigation bar item using Bootstrap 4

My navigation bar is functioning properly with single-line items, but encounters alignment issues when dealing with multi-line items: <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav ml-auto"> ...

Excessive content spilling over the div container

Hello everyone I've been trying to set up a div that includes an image, a title, and some text. I want the image to be aligned on the left side, with the title and text following on the right. However, I'm having an issue where the text is overf ...

Why is the Material UI React select not selecting all children except for the last one?

I have a challenge with selecting specific children: const useStyles = makeStyles(theme => ({ icons: { "&>*": { backgroundColor: "red", }, }, })) This is how it looks in JSX: <Grid item> < ...