When the screen size is decreased, one card begins to appear behind another card

In my attempt to create a set of responsive cards using Bootstrap, I have written the following code for the cards:

                         <div class="col-xl-4 col-md-6 col-sm-6 p-2">
                            <div class="card shadow" style="width: 16rem;">
                                <div class="inner">
                                    <img class="card-img-top" src="images/1.jpeg" alt="Card image cap">
                                </div>
                                <div class="card-body">
                                    <h5 class="card-title">Location 1</h5>
                                    <p class="card-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.
                                        Beatae maxime eaque eligendi fugit dolores odit. Corrupti repellat aperiam.
                                    </p>
                                    <div class="justify-content-between">
                                        <!-- <a href="#" class="btn btn-primary">Learn more</a> -->
                                        <div class="ml-2">
                                            <i class="fas fa-video fa-lg"></i>
                                            <i class="fas fa-restroom fa-lg ml-2"></i>
                                            <span class="ml-5">
                                                <i class="fas fa-bolt text-warning fa-lg">10</i>
                                                <i class="fas fa-bolt text-success fa-lg ml-2">8</i>
                                            </span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

Along with this code, I have added some additional CSS styles:

.inner {
        overflow:hidden;
    }

    .inner img {
        transition: all 1.5s ease;
    }
    .inner img:hover{
        transform:scale(1.5);
    }
    .card-img-top {
        width: 100%;
        height: 25vh;
        object-fit: cover;
    }

My goal is to make the images inside the card scale up when hovered over. This functionality works correctly, but I'm experiencing an issue where the cards stack on top of each other when I resize the window size. https://i.sstatic.net/8WPh0.png

I am struggling to figure out why this stacking behavior is occurring.

Answer №1

There is an issue with card overlapping another card, so the solution is to apply z-index: 1000. Here's the CSS code snippet that should work:

  .card{
        z-index: 1000;
    }
    .inner {
        overflow: hidden;
    }

    .inner img {
        transition: all 1.5s ease;
    }

    .inner img:hover {
        transform: scale(1.5);
    }

    .card-img-top {
        width: 100%;
        height: 25vh;
        object-fit: cover;
    }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
    integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
    integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84f4ebf4f4e1f6aaeef7c4b5aab5b2aab4">[email protected]</a>/dist/umd/popper.min.js"
    integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
    integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous">
</script>


<div class="row">
<div class="col-xl-4 col-md-4 col-sm-6 p-2">
    <div class="card shadow" style="width: 16rem;">
        <div class="inner">
            <img class="card-img-top" src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRQ6mhz8QnD2r1COMuWG4RZnrAzrgFwQHvC7QbIC3cSL6pbYUpL&usqp=CAU" alt="Card image cap">
        </div>
        <div class="card-body">
            <h5 class="card-title">Location 1</h5>
            <p class="card-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.
                Beatae maxime eaque eligendi fugit dolores odit. Corrupti repellat aperiam.
            </p>
            <div class="justify-content-between">
                <!-- <a href="#" class="btn btn-primary">Learn more</a> -->
                <div class="ml-2">
                    <i class="fas fa-video fa-lg"></i>
                    <i class="fas fa-restroom fa-lg ml-2"></i>
                    <span class="ml-5">
                        <i class="fas fa-bolt text-warning fa-lg">10</i>
                        <i class="fas fa-bolt text-success fa-lg ml-2">8</i>
                    </span>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="col-xl-4 col-md-4 col-sm-6 p-2">
    <div class="card shadow" style="width: 16rem;">
        <div class="inner">
            <img class="card-img-top" src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcRQ6mhz8QnD2r1COMuWG4RZnrAzrgFwQHvC7QbIC3cSL6pbYUpL&usqp=CAU" alt="Card image cap">
        </div>
        <div class="card-body">
            <h5 class="card-title">Location 1</h5>
            <p class="card-text">Lorem ipsum dolor sit amet consectetur adipisicing elit.
                Beatae maxime eaque eligendi fugit dolores odit. Corrupti repellat aperiam.
            </p>
            <div class="justify-content-between">
                <!-- <a href="#" class="btn btn-primary">Learn more</a> -->
                <div class="ml-2">
                    <i class="fas fa-video fa-lg"></i>
                    <i class="fas fa-restroom fa-lg ml-2"></i>
                    <span class="ml-5">
                        <i class="fas fa-bolt text-warning fa-lg">10</i>
                        <i class="fas fa-bolt text-success fa-lg ml-2">8</i>
                    </span>
                </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

Comparing hardware-accelerated CSS3 animations, transitions, and jQuery animate for mobile devices

While developing my app using PhoneGap and jQuery, I encountered a dilemma regarding animations. Initially, I relied on what I knew best - jQuery animate - to create smooth movements. However, discussions about hardware acceleration caught my attention. ...

Reducing the Distance Between Columns in Bootstrap 4

I am currently working on embedding two websites onto my own website. The idea is to showcase these websites side by side within a custom-sized iframe that adjusts responsively based on the viewport size. To achieve this, I am utilizing Bootstrap 4's ...

Create a line with elements that end on the next line without taking up the full width

In a row of three links, I want the third one to be on the next line, but using .new-line { display:block; } makes the link 100% width on the next line, causing the entire area to be clickable. I also have content in the :before that should appear inline w ...

Within a container, there are two divs separated by a white bar

Hello everyone, I am in need of creating a unique slideshow for my website and I want to start by splitting a div into two sections using a slightly skewed diagonal line that is either semi-transparent black or solid white. I have searched extensively onli ...

The Javascript code fails to execute after other scripts have been employed

Trying to create an expanding search bar that expands upon button click and collapses when clicking elsewhere on the page. The issue I'm facing is that everything works well initially, but after the second script hides the input field on a click outsi ...

How can I duplicate or extract all the formatting applied to a specific text selection in Ckeditor?

I am currently utilizing CKEditor version 3.6 within my Asp.net MVC 3 Application. One of my tasks involves creating a Paint format option similar to Google Docs. I am looking to integrate this feature into CKEditor. Is there a way in CKEditor to transfe ...

Ensure the table body scrolls the full height of the page while maintaining a fixed header when the table is out of view

My goal is to implement scroll bars for overflowed content within a single table on the page. Despite reading numerous posts on this topic and experimenting with various methods like setting height to 100% or using flex layout, I still can't seem to a ...

What to do when Google Font fails to load and how to define an alternative font styling

Can anyone help me out with a solution? I am facing an issue with google fonts not working in Safari on my website. Is there a way to instruct the browser to switch to a different style when the font is not supported? Below is the CSS code I am currently u ...

Prolong the ultimate position of the initial animation for the translated object

I understand that this question has been asked multiple times before, but I am seeking a fresh approach to these animations. Issue: The second box contains multiple animations, and I am trying to achieve the same effect as the first one. However, it seem ...

Hide the background when the modal appears

I have successfully implemented a jQuery CustomBox modal on my website. However, I am facing an issue with hiding the content div behind the modal once it pops up. My goal is to make the content div reappear after the modal has been closed. You can view a ...

Issue with navigating previous and next slides in Bootstrap carousel

I'm currently facing an issue where when I try to navigate left/right through pictures on my page, it ends up moving slightly downwards instead. Despite following a tutorial to resolve this problem, there seems to be a missing piece of code that I can ...

Preserving distance between absolute elements

I'm facing an issue with my menu animation using jQuery. In order to achieve the desired effect, I am forced to use position: absolute. My challenge is maintaining consistent spacing between each text string, especially since they vary in width. Unfor ...

Automatically remove the entered data

Let's say I have a text input field with the initial value of "insert text here" coded like this: <input type="text" value="insert text here" /> What I want is for the text inside the input field to disappear automatically when the user clicks ...

Modifying the Carousel Interval on the Fly: A Guide

I've been trying to figure out how to adjust the interval time on a Bootstrap carousel. I know you can set it initially using: $('.carousel').carousel({interval: 1000 }); But what if I want the interval to change to 2 seconds after, let&ap ...

Customizing CSS styles for designated sections

Within my code, I currently have the <p> style set to a font-size of 16px. However, I would like to increase the font-size to 20px for any <p> text within a "card" element, without needing to add a separate font-class to each <p> individu ...

What is the best way to add padding to both the TextField input and label components within Material UI?

Recently, I've integrated Material UI into my project and set up a TextField for a form field. However, I'm facing an issue where applying padding to the input field doesn't affect the label as well. <TextField sx={{ display: &q ...

Utilizing the vertical grid layout with columns in Bootstrap for HTML websites

I have been attempting to showcase the attached image below in a vertical column-wise grid view using Bootstrap in HTML. Can someone provide me with ideas on how to achieve this? Currently, I am displaying a row-wise column grid with reference to Grid sys ...

Do you know where I can locate the HTML and CSS pertaining to the search results page

I'm looking for a way to present search results on my website that resembles the Google search results, creating a familiar interface for users. Is there anyone who knows where I can obtain the HTML and CSS code that produces the same style as Google& ...

Can the navbar hamburger in Bootstrap be displayed at a screen size of 992px?

How can I display the bootstrap navbar Hamburger at md(992px) Screen? Here is the code snippet I am currently using: https://i.sstatic.net/OqBTQ.png Any suggestions on what steps I should take? ...

Ways to target other links exclusively during hover effect on a single link

I've been attempting to shrink all other links when one link is hovered over, but I'm only able to make the links after the hovered one shrink. .navlink { width: 100px; display:inline-block; background-color: red; } .navlink:hover~.navl ...