Can the card overlay slide appear solely on top of the image?

I am trying to create a gallery section of cards using Bootstrap 4 where I want the user to hover over each card and have an overlay slide or fade in, covering only the image. Currently, the overlay slides in over the entire card instead.

I have been struggling to make the overlay fit just the card. Right now, when I set the width and height to 100%, it covers the entire card, but if I remove that, the overlay becomes small and slides in over the gap between the image and the border. Any suggestions on how to achieve this?

Here is the HTML of one of the cards:

<div class="card mt-6">
  <div class="px-3">
    <div class="card-overlay">
      <h1 class="card-overlay-heading">Meet Brian!</h1>
      <script src="https://fast.wistia.com/embed/medias/.jsonp" async></script>
      <script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>
      <span class="wistia_embed wistia_async_ popover=true popoverContent=link" style="display:inline;position:relative">
                                        <a href="#"><i class="fas fa-play"></i></a></span>
    </div>
    <img src="images/Lorraine.png" class="card-img" alt="">
  </div>
  <div class="card-body">
    <h6 class="card-title mb-0 text-uppercase">Mark D</h6>
    <p class="card-text mb-3  text-green fw-bold">Web</p>
  </div>
</div>

CSS:

.card {
  position: relative;
  overflow: hidden;
}

.card:hover .card-overlay {
  left: 0;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: -100%;
  background-color: rgba(85, 211, 150, 0.6);
  color: #fff;
  height: 100%;
  width: 100%;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  transition: left .7s;
}

Answer №1

To achieve the desired effect, simply include position: relative to the wrapper of the image. This will make the overlay relative to the card instead of the entire card itself. Take a look at the demo below:

.card {
  position: relative;
  overflow: hidden;
}
.card > div { /* ADDED THIS */
  position: relative;
}

.card:hover .card-overlay {
  left: 0;
}

.card-overlay {
  position: absolute;
  top: 0;
  left: -100%;
  background-color: rgba(85, 211, 150, 0.6);
  color: #fff;
  height: 100%;
  width: 100%;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  transition: left .7s;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" />
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

<div class="container">
  <div class="card mt-6" style="width:300px">
    <div class="px-3">
      <div class="card-overlay">
        <h1 class="card-overlay-heading">Meet Brian!</h1>
        <span class="wistia_embed wistia_async_ popover=true popoverContent=link" style="display:inline;position:relative">
                                    <a href="#"><i class="fas fa-play"></i></a></span>
      </div>
      <img src="https://via.placeholder.com/50" class="card-img" alt="">
    </div>
    <div class="card-body">
      <h6 class="card-title mb-0 text-uppercase">Mark D</h6>
      <p class="card-text mb-3  text-green fw-bold">Web</p>
    </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

Bootstrap grid. Instead of moving to the next row, scroll horizontally when the content overflows

Here is the code snippet: <div class="row shochatgroup"> <div *ngFor="let message of messages" class="col-auto"> <button *ngIf="message.state.attributes.shochatpaid > 0 && message.state.at ...

Is it possible to adjust the ul width to match its parent's width using CSS?

Whenever I type in a search, a list is displayed. The issue arises on small devices where the width of the list exceeds that of the search input or its parent container, which should not happen. On small devices, it should always look like this: Example L ...

The issue of URL not updating with Twitter Bootstrap tabs

Currently, I am utilizing Twitter Bootstrap along with its "tabs" feature. Here is the code snippet that I have implemented: <ul class="nav nav-tabs"> <li class="active"><a data-toggle="tab" href="#add">add</a></li> ...

I currently have two responsive menus and I'm trying to figure out how to modify the javascript so that when one menu is opened, the other

I am facing an issue with my responsive menus on a webpage, similar to the example provided in the jsfiddle link below. Currently, when one menu is open and I click on another, both remain open. How can I modify the JavaScript code so that when one menu op ...

Here's a unique version: "Steps for replacing an outdated chart with a new one using Chart.js and

Is there a way to remove an old chart when the user clicks a button to retrieve a new chart? I understand that the existing chart needs to be destroyed before a new one is generated, but currently, the code does not support destroying non-globally create ...

What is the best way to add a hover effect to two different objects simultaneously?

I am facing an issue with two div's, A and B. I want to hover over DIV A and display DIV B without hiding it when moving the mouse from DIV B. <div id="a"><img src="images...." class="profile" id="options" /></div> <div id="b"> ...

What is the best way to position a search icon on the right side using CSS?

I am trying to figure out how to display a search icon image on the right side using CSS, but so far I have been unsuccessful. Here is the code that I have: The CSS code: .search { background: url(../images/icons/search.png) no-repeat; display:in ...

Unable to hide the mobile menu button

https://i.sstatic.net/5rdYY.pngI am currently working on a fun website project . I am facing an issue with the mobile menu button not disappearing using display:none in Safari on my iPhone when in landscape mode, even though it works fine in Chrome. My g ...

Laravel Tutorial: Utilizing for and foreach Loops to Showcase Data in Blade Template

I am trying to use a for and foreach loop to display data based on a template table. However, I am running into an issue where the else conditions always display an index of their own. My expectation is as follows: https://i.stack.imgur.com/tqDSn.png Th ...

I have a vision of creating a unique Countdown Stopwatch that meets all my

I'm looking to create a custom countdown stopwatch where I can set the time and watch it count down to 0:00. The stopwatch should have three buttons: Start, Stop, and Reset. I've searched multiple websites for what I need but haven't found ...

Ways to eliminate additional whitespace in CSS Grid styling techniques

Currently, I am utilizing material ui to establish a grid system for showcasing videos in 2 rows. While I have successfully set up the general layout, I am facing difficulty in eliminating the white space/padding between the elements. Despite trying nowrap ...

:active state not functioning correctly

I've utilized the :after and :before pseudo-elements to create a border effect when hovering over the navigation links. I've been trying to achieve the same border effect in the :active pseudo-class as well. Can someone please guide me on how to ...

Manipulate the content of any webpage without using external extensions by injecting your own HTML, CSS, and JavaScript code

I am currently following a tutorial on how to draw shapes on a local webpage using Canvas. I came across this helpful article on Html5 canvas paint. Everything is going smoothly, but now I am interested in replicating the drawing functions/CSS/HTML and "i ...

Ignored are the white spaces within a pre tag

From what I understand, the 'pre' tag is supposed to collapse all white spaces and tabs into one space. However, I have noticed that this doesn't happen for me. I'm curious as to why this may be the case. Could it possibly be dependent ...

Retrieve the values and IDs for every span element within the form

I have been attempting to retrieve all span elements within a form and make them editable input text fields. Once you click away, they should revert back to span elements. I will provide a live example in the attached fiddle. I tried my hand at it, but the ...

Tips for incorporating Bootstrap classes into a React project, setting the className attribute to an empty string

After setting up Bootstrap and Create-React-App using npm on my local machine, I proceeded to create a new React app. The first component I worked on was counter.jsx: import React, { Component } from 'react'; class Counter extends Component { ...

JavaScript taking over the HTML footer content

I'm attempting to update the content of my footer without modifying the HTML by including a class or an id. HTML: <footer> <div> Lorem ipsum dolor sit amet, consectetur adipisicing elit. </div> </footer> Java ...

Additional cushioning is added when utilizing the X-UA-Compatible meta tag

After experimenting with various meta tags in the <head> section of my static HTML page, I have found that using <meta http-equiv="X-UA-Compatible" content="IE=edge" /> allows me to access newer CSS elements such as table:last-of-type in IE9. ...

ng2-table ways to customize the appearance of a particular row

Hey there, I'm currently new to Angular 2 and working with ng2-table. I've successfully added a table like the one shown here to my website. Now, I'm trying to figure out how to add color to specific rows within the table. Following the ste ...

The issue arises when trying to implement CSS keyframes with a CSS image slideshow

I'm currently troubleshooting a CSS slideshow that isn't functioning properly. The issue lies within the keyframes. I'm attempting to make the images come down from the top mask and then have the previous image go back up into the mask. This ...