Issue with Bootstrap card collapsing and merging with other cards

I am using Bootstrap to design a grid of cards, but I am facing an issue where all the cards are merging together when I resize the screen. This issue occurred when I attempted to position the icons to appear at the top left of the card and the bottom middle while adding a link tag to the image.

<div class="col-sm-6 col-md mt-3">
  <div class="card" style="position: relative;">
      <a href="#" style="position: absolute; top: 0; left: 0; z-index: 2; width: 100%; height: 100%; pointer-events: none;">
          <img src="https://images.igdb.com/igdb/image/upload/t_cover_big/co7lbb.png" alt="" style="pointer-events: auto;">
      </a>
      <div class="icon-placeholder" style="position: absolute; top: 0; left: 0; z-index: 3;">
          <!-- Heart icon on top left -->
          <i id="heart" class="fas fa-heart heart-icon top-left-icon"></i>
          <!-- Other icons on bottom -->
          <div class="bottom-icons" style="position: absolute; bottom: -300px; left:100px;">
              <i class="fas fa-comment comment-icon p-2"></i>
              <i class="fas fa-share share-icon p-2"></i>
              <!-- ... add more icons as needed -->
          </div>
      </div>
  </div>

---- CSS stylesheet ----

  display: flex;
  justify-content: space-evenly;
  margin-top: auto; /* Push the bottom icons to the bottom */
} 


.icon-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
}

.card img {
  border-radius: 20px;
  max-height: 320px;
  max-width: 320px;
  object-fit: cover;
  display: block;
}

    .card {
  position: relative;
  border-radius: 20px;
  background-color: #ffffff00;
  max-width: 264px;
  max-height: 352px;
  transition: transform .2s; /* Add transition property for smooth animation */
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

Answer №1

After attempting to arrange the icons, it was discovered that there was a mistake in the code. The image wrapper and Icons wrapper were incorrectly positioned, causing the cards to overlap. This issue has been rectified by replacing the inline CSS with bootstrap classes and removing any redundant CSS. Below is the modified code snippet:

.card img {
  border-radius: 20px;
  max-height: 320px;
  max-width: 100%;
  width: 100%;
  object-fit: cover;
  display: block;
}

.heart-icon {
  position: absolute;
  top: 10px;
  left: 10px;
}

.bottom-icons {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
}
<link href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet">
  
  
<div class="container">
    <div class="card my-3">
        <div class="card-body">
            <div class="row g-3">
                <div class="col-6 col-md-4 col-lg-3">
                    <div class="position-relative">
                        <a href="#" class="pe-none">
                            <img src="https://images.igdb.com/igdb/image/upload/t_cover_big/co7lbb.png" alt="" class="pe-auto">
                        </a>
                        <div class="icon-placeholder">
                            <i id="heart" class="fas fa-heart heart-icon top-left-icon text-white"></i>

                            <div class="d-flex justify-content-center text-white bottom-icons">
                                <i class="fas fa-comment comment-icon p-2"></i>
                                <i class="fas fa-share share-icon p-2"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-6 col-md-4 col-lg-3 mt-3">
                    <div class="position-relative">
                        <a href="#" class="pe-none">
                            <img src="https://images.igdb.com/igdb/image/upload/t_cover_big/co7lbb.png" alt="" class="pe-auto">
                        </a>
                        <div class="icon-placeholder">
                            <i id="heart" class="fas fa-heart heart-icon top-left-icon text-white"></i>

                            <div class="d-flex justify-content-center text-white bottom-icons">
                                <i class="fas fa-comment comment-icon p-2"></i>
                                <i class="fas fa-share share-icon p-2"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-6 col-md-4 col-lg-3 mt-3">
                    <div class="position-relative">
                        <a href="#" class="pe-none">
                            <img src="https://images.igdb.com/igdb/image/upload/t_cover_big/co7lbb.png" alt="" class="pe-auto">
                        </a>
                        <div class="icon-placeholder">
                            <i id="heart" class="fas fa-heart heart-icon top-left-icon text-white"></i>

                            <div class="d-flex justify-content-center text-white bottom-icons">
                                <i class="fas fa-comment comment-icon p-2"></i>
                                <i class="fas fa-share share-icon p-2"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-6 col-md-4 col-lg-3 mt-3">
                    <div class="position-relative">
                        <a href="#" class="pe-none">
                            <img src="https://images.igdb.com/igdb/image/upload/t_cover_big/co7lbb.png" alt="" class="pe-auto">
                        </a>
                        <div class="icon-placeholder">
                            <i id="heart" class="fas fa-heart heart-icon top-left-icon text-white"></i>

                            <div class="d-flex justify-content-center text-white bottom-icons">
                                <i class="fas fa-comment comment-icon p-2"></i>
                                <i class="fas fa-share share-icon p-2"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </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

Gradually appear/disappear div element with a delay added

Storing divs in an array and deleting them after appending is my current method. Now, I'm looking to incorporate a fade-in and fade-out effect on each div with a delay. Check out this code snippet : var arr = $(".notification"); function display ...

Flexbox ancestor causing Bootstrap 5 Carousel width to double

A peculiar issue arises with the Bootstrap 5 Carousel placed inside a Flexbox where it unexpectedly expands in width (pushing other flex-items aside) when transitioning between images. This behavior persists even when the immediate container is set to disp ...

initiate changes to the application's style from a component nested within the app

I'm looking to update the background color of the entire page, including the app-nav-bar, when I'm inside a child component. When I navigate away from that component, I want the default style to be restored. Any suggestions on how to achieve this ...

Incorporating CSS and JS files into a WordPress theme

To incorporate Css & Js files into my website pages, I plan to insert the following code into the functions.php file: function cssjsloading(){ wp_enqueue_style('bootstrap-rtl', get_template_directory_uri() . '/css/bootstrap-rtl.css&apo ...

Grid items in Material UI are not positioned next to each other

I am encountering an issue with the Grid component in material-ui. The grid items are currently stacking below each other instead of beside each other, and I'm unsure of what is causing this behavior. My intention is for the grid items to stack on top ...

Laravel application faces issues with URL rewriting generating incorrect URLs in compiled CSS files

Having some trouble compiling Font Awesome SCSS files in my Laravel application. I installed Font Awesome using NPM, and the compiled CSS is stored in the 'public/css/' folder while a 'public/fonts/' folder was also created. However, th ...

jQuery is great at adding a class, but struggles to remove it

When you click on an anchor with the class .extra, it adds the "extra-active" class and removes the "extra" class. However, when you click on an anchor with the extra-active class, it does not remove the extra-active class and replace it with extra. Here ...

Comparing Strict CSS with Hacky CSS - Which is the Better Choice?

When working with CSS, it becomes evident fairly quickly that certain styles are not universally compatible across different browsers. For instance, achieving a semi-transparent PNG required a convoluted solution for Internet Explorer like: filter: pro ...

Positioning Images with CSS Backgrounds

I am looking to create a fluid background that stretches widthwise, while adjusting its height based on the content. If the content is smaller, I want the background to be truncated. However, if there is a lot of information, I would like the background to ...

Which component from the Bootstrap library would be best suited for my needs?

I am looking to create a basic 6-page website. Here is the code for my main page: <html> <style> .ali{ width:170px; text-align:center; } footer{ background:#333; color:#eee; font-size:11px; padding-top: 25px; p ...

Unique layout design that organizes calendar using nested divs with flexbox - no

I am having difficulties achieving the desired outcome with my calendar header layout implemented using flexbox for the years, months, and days. What could be the issue? Is it due to the structure of the HTML or is there something missing in the CSS? The ...

"Maximizing Space: A Guide to Setting BootStrap Navbar on the Right Side of the Page with Dropdown Width

Take a look at the image below. There is a navbar toggle button on the upper right corner of the page. When I expand it, the dropdown items occupy the entire width of the page, causing an issue where clicking anywhere within the red box triggers the dropdo ...

Tips for applying personalized CSS to individual Toast notifications in Angular

MY QUESTION : I am looking to customize the CSS of a single toast used in Angular components. While there may be multiple toasts, I specifically want to style one particular toast differently. For example, the toast image can be viewed here: example toast ...

What is the best way to create pages that showcase 10 posts each?

Currently, I am facing a challenge with displaying 100 posts using the Fetch API on one single page. I am looking for a way to create separate pages where each page would showcase only 10 posts. Below is my existing JavaScript code: fetch('htt ...

When resetting the function, make sure to move the class to the closest sibling element

I am currently utilizing a slider that employs the .prev and .next jQuery functions to toggle the active class, indicating which slide is being displayed. Here is the code responsible for this functionality. It identifies the current sibling with the acti ...

JavaScript alert box

I'm fairly new to the world of web development, with knowledge in CSS & HTML and currently learning TypeScript. I'm attempting to create a message icon that opens and closes a notifications bar. Here's where I'm at so far: document.getE ...

AngularJS: Showcase HTML code within ng-view along with its corresponding output displayed in a navigation format such as Html, Css, JS, and Result

Currently, I am working on a web application. One of the screens, screen-1, consists of a series of buttons labeled 'Code'. When a user clicks on any of these buttons, it loads a different HTML page, screen-2, in the ng-view using $location.path( ...

Problem with CSS hovering on images when hovering on links?

While attempting to add 2 hover images to my website, I encountered an issue where a black border appeared in the middle of the images. This was caused by the hover effects on the links. Below is the code snippet: a:hover,a:active { color:Black; o ...

Internet Explorer 9 users experience a sudden blank page display

Are there any effective methods for diagnosing why a page suddenly becomes blank in Internet Explorer? I am aware that switching to Compatibility Mode 7 is an option, however dealing with the quirks of IE7 can be even more challenging. ...

Utilize the appendTo() function and make a switch to dynamically insert content stored in variables into a specified

I am working on developing a page with a central content div, where users have the ability to choose various options that will introduce different additional content. This added content will then present more opportunities for adding new elements, ultimate ...