Can a hover effect be applied directly to the pseudo element "after"?

I have been trying to implement a hover effect on the after pseudo-element itself, where its background changes when hovered over. However, my CSS code does not seem to be having any effect:

.card::after:hover {
  filter: drop-shadow(30px 10px 4px #4444dd);
  background-color: red;
}

This is for a card design, and I want the "Check it out" pseudo-element to change its background and display a shadow upon hovering over it. Is there a way to achieve this functionality?

.card {
  --fs-card: 1.2rem;
  background-color: var(--clr-light);
  width: 200px;
  height: 90%;
  max-height: 31.25rem;

  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 5px;
  box-shadow: 3px 3px 8px rgb(0, 0, 0);
  overflow: hidden;
  justify-content: space-between;
  position: relative;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.215, 0.61, 0.355, 1);
}
.card:hover {
  transform: scale(1.05);
}

.card::after {
  opacity: 0;
  content: "Check it out";
  font-family: "Myriad pro";
  font-size: 1.2rem;
  position: absolute;
  z-index: 3;
  left: 3px;
  top: 3px;
  background-color: #0c44ddd2;
  color: var(--clr-light);
  border-radius: var(--btn-border-radius);
  padding: 0.1rem 0.6rem;
  transition: all 0.5s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.card:hover::after {
  opacity: 1;
}

.card::after:hover {
  filter: drop-shadow(30px 10px 4px #4444dd);
  background-color: red;
}

.article-img-container {
  height: 60%;
  width: 100%;
  background-color: white;
}

.article-img {
  object-fit: contain;
  object-position: center;
  height: 100%;
  width: 100%;
}
<div class="card">
                <div class="article-img-container">
                  <img
                    class="article-img"
                    src="https://files.refurbed.com/ii/apple-watch-series-6-alu-40mm-1613627678.jpg?t=resize&h=600&w=800"
                    alt=""
                  />
                </div>
                <div class="article-info-container">
                  <p class="article-title">Smart Watch S6</p>
                  <p class="article-price clr-primary">€ 266.99</p>
                </div>
                <button class="btn btn-card">ORDER NOW</button>
</div>
        

Answer №1

As far as I know, achieving this using the "after" pseudo element may not be possible, since a pseudo element is not a real DOM element.

Instead, I would recommend utilizing the relative and absolute positioning properties you already have on your element. By making your "check it out" text a real absolute position element and applying CSS hover effects on the card, you can achieve the desired result.

.card {
  --fs-card: 1.2rem;
  background-color: var(--clr-light);
  width: 200px;
  height: 90%;
  max-height: 31.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-radius: 5px;
  box-shadow: 3px 3px 8px rgb(0, 0, 0);
  overflow: hidden;
  justify-content: space-between;
  position: relative;
  cursor: pointer;
  transition: all 0.4s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.card:hover {
  transform: scale(1.05);
}

.card-checkout {
  opacity: 0;
  font-family: "Myriad pro";
  font-size: 1.2rem;
  position: absolute;
  z-index: 3;
  left: 3px;
  top: 3px;
  background-color: #0c44ddd2;
  color: var(--clr-light);
  border-radius: var(--btn-border-radius);
  padding: 0.1rem 0.6rem;
  transition: all 0.5s cubic-bezier(0.215, 0.61, 0.355, 1);
}

.card:hover .card-checkout {
  opacity: 1;
}

.article-img-container {
  height: 60%;
  width: 100%;
  background-color: white;
}

.article-img {
  object-fit: contain;
  object-position: center;
  height: 100%;
  width: 100%;
}

.card-checkout:hover {
  filter: drop-shadow(30px 10px 4px #4444dd);
  background-color: red;
}
<div class="card">
  <div class="article-img-container">
    <img class="article-img" src="https://files.refurbed.com/ii/apple-watch-series-6-alu-40mm-1613627678.jpg?t=resize&h=600&w=800" alt="" />
  </div>
  <div class="article-info-container">
    <p class="article-title">Smart Watch S6</p>
    <p class="article-price clr-primary">€ 266.99</p>
  </div>
  <button class="btn btn-card">ORDER NOW</button>
  <div class="card-checkout">
    Check it out
  </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

Implement a function that runs upon Page Load using Javascript

Here is some Javascript code that loads a map with different regions. When you hover or click on a country, additional information about that country is displayed on the right side of the map. I would like to have a random country already displaying infor ...

Determine the character's position in an input field by tracking mouse movements

I am in need of a way to determine the position of a character in an input field based on mouse movement. For example, if the input field contains the value 'abcde' and I hover my mouse over the character 'a', the position should be ...

Disable page scrolling while enabling scrolling for specific elements with overflow using JQM

Is there a way to stop the page from scrolling on a jQuery Mobile page while still allowing a specific element with overflow set to scroll to be scrolled by the user? The challenge is that the length of the page may vary slightly, exceeding 100% on differe ...

Make the background image draggable while maintaining its size with background-size:cover

I'm working on a fixed div with an image as the background, set up like this: <div style=' width:230px; height:230px; background-repeat: no-repeat; background-image:url(img/myimage.jpeg) background-size: cover;'&g ...

What methods can be employed to maintain a consistent width for a multi-line span that aligns with the content?

Inside a div, I have 2 spans. When the content of the first span is short enough to fit on one line, the span's width matches the text content and positions the second span next to it. If the content of the first span is long and causes it to wrap, t ...

jQuery: Set default option selected or reset value

I'm attempting to change the value of the nearest select option dynamically. $(document).ready(function () { $('.limitation_points').hide(); $('.field .limitSelected').each(function () { $(this).change(function ( ...

Mastering TailwindCSS: Enhancing your design with group-hover utilities for top, bottom, right, and left

In a div, there is an <img> tag and a <button> tag. I used group in the className of the div and group-hover:opacity-0 in the img tag, and it worked correctly. However, when I applied group-hover:top-1/2 to the <button> tag, it did not wo ...

How can ListSubheader in Material-UI be customized to match the style of iOS UITableView?

Here is the current appearance of my ListSubheader. https://i.stack.imgur.com/HAzTA.png Currently, it is just aligned to the left. However, the default header view in UITableView on iOS looks like this: https://i.stack.imgur.com/F9Amv.png It features ...

Choose from an array of over 50,000 row options

I am currently facing an issue with my database which contains approximately 50,000 records, all related to business partners. Currently, I am using the following code: <select name="selection"> -- some while loop <option></option> (thi ...

Pressing a button within an HTML table to retrieve the corresponding value in that row

How can I click a button inside an HTML table, get the value on the same row and pass it to an input field called FullName? Thanks for your help! <td><?php echo $r['signatoryname'] ?></td> <td ...

Undisclosed iFrame technique for uploading files - issue with nested forms

This question seems to be more related to JavaScript/jQuery/DOM rather than Rails, but it's all linked to how I integrated it in Rails. I'm currently working on allowing users to upload multiple photos while creating a new object (auction). The c ...

The exact location of the mouse is currently unknown

When I try to double click on a td, it should change the value of an input field to display the coordinates of the mouse cursor. However, instead of showing the coordinates, it just displays unidentified. How can I modify this script to fix this issue? Her ...

OpenCart glitch: Customer login dropdown menu consistently clipped on various stores

This situation arises specifically when multiple stores are set up in OpenCart. When filtering by customer name on the admin side and only one customer is displayed in the results list, the "Login into Store" dropdown menu may be cut off (as shown in the f ...

Adjust the placement of a div element

This snippet shows the CSS styles being used: <style type="text/css"> #search_results{position:relative;height:369px;overflow:auto} #floating{background-color:#eee;padding:15px;position:absolute;bottom:0px} </style> I am facing an issue with ...

An issue with Destination-Out Composition in HTML5 Canvas

While working on a canvas, I have encountered an issue with deleting a portion of a curve I have drawn. Specifically, I need to remove the last 25% of the curve after it is complete and keep only the first 75%. However, when attempting to delete the lines ...

Determine if the user's request to my website is made through a URL visit or a script src/link href request

Presently, I am working on developing a custom tool similar to Rawgit, as a backup in case Rawgit goes down. Below is the PHP code I have created: <?php $urlquery = $_SERVER['QUERY_STRING']; $fullurl = 'http://' . $_SERVER['SE ...

The Zoom CSS property seems to be experiencing some issues on the Firefox browser

After researching the issue, I discovered several solutions involving css3 transition techniques. Currently, I have been using {zoom:1.5} for all of my buttons. However, this method does not work on Firefox. When attempting to implement the transition pro ...

Additional section for positioning beyond designated spot

If you want to understand better, take a look at this link: Here's the scenario: I have one article with 2 CSS columns. In the first column, there is text and images for the article, while in the second column, I want to place aside elements like tex ...

Enhance the worth of text box

Is there a way to adjust the value of a textbox by one on keyup, keydown, or tap events? Check out this example. Here is the HTML structure: <div class="right-content" id="rc-0" style="height: 250px;"> <div class="right-cont-main" id="rcm-0" s ...

Enhance drop-down menus in Bootstrap 4 by making the entire li area clickable

Currently working on a complex bootstrap 4 menu button with multiple levels and encountering an issue with the selectable area. To demonstrate the problem, I have marked the current clickable area with black borders and highlighted the desired clickable a ...