I am looking to achieve a hover effect with CSS that blurs an element upon hovering

I need help fixing the blur effect on my button. When I hover over it, the button becomes blurred even though I don't want that. I tried adjusting the z-index values but it didn't work.

There seems to be an error in the snippet where I want only the main card to blur, not the button.

Can someone suggest how to resolve the issue with the button blur?

I attempted using z-index and child elements in CSS without success.

I'm a beginner in CSS so any assistance is much appreciated.

To review and possibly edit, visit: JS Fiddle

CODE:

.main-card{
  width: 326px;
  height: 360px;
  background-color: white;
  border-radius: 15px;
  display: inline-grid;
  margin: 60px;
  padding-bottom: 21px;
  z-index: 1;
}

.main-card:hover{
  webkit-filter: blur(1px); /* Chrome, Safari, Opera */
  filter: blur(1px);
}

.rafflelink{
  filter: blur(0px);
  z-index: 2;
}

.main-card > .rafflelink{
  opacity: 0;
  height: 50px;
  position: absolute;
  width: 200px;
  align-self: center;
  justify-self: center;
  z-index: 2;
}

.main-card:hover > .rafflelink{
  opacity: 1;
  filter: none;
}

.header-card{
  font-family: 'Poppins', sans-serif;
  text-align: center;
  height: 20px;
  background-color: white;
  border-top-left-radius:15px ;
  border-top-right-radius:15px ;
}
.img-bg-card{
  background-color:#0779e4;
  text-align: center;
}
.img{
  height: 157px;
  padding-top: 5px;
  width: 95%;
}
.progress-bar{
  height: 16px;
  background-color: grey;
  border:solid 2px #0779e4;
}

.price-bar{
  text-align: center;
  justify-content: space-between;
  display: -webkit-flex;
  border-bottom: solid 2px cornflowerblue;
  margin-left: 40px;
  margin-right: 40px;
  margin-top: 15px;
  padding-right: 5px;
  padding-left: 5px;
}

.ticket-bar{
  text-align: center;
  justify-content: space-between;
  display: -webkit-flex;
  border-bottom: solid 2px cornflowerblue;
  margin-left: 40px;
  margin-right: 40px;
  margin-top: 15px;
  padding-right: 5px;
  padding-left: 5px;
}

.date-bar{
  text-align: center;
  justify-content: space-between;
  display: -webkit-flex;
  border-bottom: solid 2px cornflowerblue;
  margin-left: 40px;
  margin-right: 40px;
  margin-top: 15px;
  padding-right: 5px;
  padding-left: 5px;
}
.price-left,.ticket-left,.date-left{
  font-family: 'Poppins', sans-serif;
}
.price-right,.ticket-right,.date-right{
  font-family: 'Poppins', sans-serif;
}

body {
    width: 100%;
    height: 100%;
    background-color: #0695ff;
}
<body>
<div class="main" style="text-align: -webkit-center; padding-bottom: 60px;">
    <div class="main-card">
        <button class="rafflelink" href="/urun/Random Random Random">Random Click</button>
        <div class="header-card">Random Random Random</div>
        <div class="img-bg-card">
            <img class="img" src="">
        </div>
        <div class="progress-bar"></div>
        <div class="price-bar">
            <div class="price-left">Random Price:</div>
            <div class="price-right">1</div>
        </div>
        <div class="ticket-bar">
            <div class="ticket-left">Random Ticket:</div>
            <div class="ticket-right">10000</div>
        </div>
        <div class="date-bar">
            <div class="date-left">Random Date:</div>
            <div class="date-right">05/06/2021</div>
        </div>
    </div>
</div>
</body>

Answer №1

To ensure proper functionality of the absolute-positioned buttons, add position: relative to the .main-card class.

Modify the selector from .main-card:hover to .main-card:hover > * in order to blur only the children elements and not the entire .main-card. This will look like:

.main-card:hover > * {
    webkit-filter: blur(1px); /* Chrome, Safari, Opera */
    filter: blur(1px);
}

Remove the .rafflelink {} selector from the CSS as it is unnecessary.

.main-card {
    width: 326px;
    height: 360px;
    background-color: white;
    border-radius: 15px;
    display: inline-grid;
    margin: 60px;
    padding-bottom: 21px;
    z-index: 1;
    position: relative;
}

.main-card:hover > * {
    webkit-filter: blur(1px); /* Chrome, Safari, Opera */
    filter: blur(1px);
}

/*.rafflelink {
  filter: blur(0px);
  z-index: 2;
}*/

.main-card > .rafflelink {
    opacity: 0;
    height: 50px;
    position: absolute;
    width: 200px;
    align-self: center;
    justify-self: center;
    z-index: 2;
}

.main-card:hover > .rafflelink {
    opacity: 1;
    filter: none;
}

.header-card {
    font-family: "Poppins", sans-serif;
    text-align: center;
    height: 20px;
    background-color: white;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
}

.img-bg-card {
    background-color: #0779e4;
    text-align: center;
}

.img {
    height: 157px;
    padding-top: 5px;
    width: 95%;
}

.progress-bar {
    height: 16px;
    background-color: grey;
    border: solid 2px #0779e4;
}

.price-bar {
    text-align: center;
    justify-content: space-between;
    display: -webkit-flex;
    border-bottom: solid 2px cornflowerblue;
    margin-left: 40px;
    margin-right: 40px;
    margin-top: 15px;
    padding-right: 5px;
    padding-left: 5px;
}

.ticket-bar {
    text-align: center;
    justify-content: space-between;
    display: -webkit-flex;
    border-bottom: solid 2px cornflowerblue;
    margin-left: 40px;
    margin-right: 40px;
    margin-top: 15px;
    padding-right: 5px;
    padding-left: 5px;
}

.date-bar {
    text-align: center;
    justify-content: space-between;
    display: -webkit-flex;
    border-bottom: solid 2px cornflowerblue;
    margin-left: 40px;
    margin-right: 40px;
    margin-top: 15px;
    padding-right: 5px;
    padding-left: 5px;
}

.price-left,
.ticket-left,
.date-left {
    font-family: "Poppins", sans-serif;
}

price-right,
ticket-right,
date-right {
    font-family: "Poppins", sans-serif;
}

body {
    width: 100%;
    height: 100%;
    background-color: #0695ff;
}
<body>
<div class="main" style="text-align: -webkit-center; padding-bottom: 60px;">
    <div class="main-card">
        <button class="rafflelink" href="/urun/Random Random Random">Random Click</button>
        <div class="header-card">Random Random Random</div>
        <div class="img-bg-card">
            <img class="img" src="">
        </div>
        <div class="progress-bar"></div>
        <div class="price-bar">
            <div class="price-left">Random Price:</div>
            <div class="price-right">1</div>
        </div>
        <div class="ticket-bar">
            <div class="ticket-left">Random Ticket:</div>
            <div class="ticket-right">10000</div>
        </div>
        <div class="date-bar">
            <div class="date-left">Random Date:</div>
            <div class="date-right">05/06/2021</div>
        </div>
    </div>
</div>
</body>

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

Pass on styling properties to children components in React and implement them within a CSS stylesheet

Currently, I am utilizing the Dropdown component to mimic an HTML dropdown functionality. However, this component is actually comprised of divs, ordered lists, and unordered lists. My challenge lies in applying styles to specific elements with className at ...

Tips for concealing a button within an ajax response

My JavaScript page includes an AJAX call, and here is the code snippet... $("#txn_post").dialog({ modal: true, title:"Transaction", show: 'blind', hide: 'blind', width: 740, height:550, ...

Updating the source content of an iframe in real time

Currently, I am working on a search result page. The scenario involves a login page redirecting to a homepage that consists of a dropdown menu, a textbox, a button, and an iframe displaying a table with user data (firstname, lastname, middlename). Upon sel ...

implementing dynamic navigation bar, when transforming into a dropdown menu using ReactJS

I am currently utilizing a navigation bar from a Bootstrap theme within my React project. The navigation bar includes an in-built media query that determines whether it should display as a dropdown menu or not, with a toggler to handle the dropdown functi ...

Conflicting Styles in CSS

Dealing with conflicting style sheets can be a headache, especially when using multiple plug-ins each with their own set of styles. It seems like no matter what I do, conflicts arise everywhere on my page. Is there a simple solution to this problem other t ...

Personalized designing of each letter

Is there a way to style numbers without using something like <span></span>? I'm looking for a clean way to do this for each sign. Attached is an example showing a "flip clock" effect that I would like to achieve. I have come across plugi ...

Creating a responsive navigation menu using Bootstrap 4 by merging data from various MySQL tables

I am struggling to create a bootstrap 4 nav-menu using the provided SQL query and code snippets. Below are the tables: TABLE menu -------------------------------------- | id | title | url | | 1 | Home | index.php | | 2 | M ...

Serve the mobile version to mobile visitors and the desktop version to all other visitors

Can someone please explain to me how I can display the Mobile Version of a website when visiting on my phone, and the Desktop Version when viewing on anything larger than 500px? I have separately created both a Mobile Website and a Desktop Website. Is it ...

Can anyone help me troubleshoot this issue with uploading external JS scripts into my HTML code?

I'm currently facing an issue with my HTML document where the external js file is not loading. Here's a snippet of the HTML: <!DOCTYPE html> <html> <head> <title>...</title> <meta name="viewport" conten ...

The webpage declined to show the content from 'https://www.youtube.com/watch?v=oKZRsBjQJOs' within a frame due to the 'X-Frame-Options' being set to 'sameorigin'

I'm struggling to incorporate a YouTube video into my website using a dynamic URL. I attempted to create a pipe for this purpose, but unfortunately it is not functioning properly. Here's the HTML code snippet from my file: <iframe width="6 ...

Mastering the art of using div boxes in boxing form

When I box in information using divs, I've noticed that sometimes the wrapping boxes don't fill out the space completely. This can result in elements from other wrappers encroaching into the box area. For example: <div> <div style="le ...

Automating web browsing within an HTML/web application

After extensive research, I am exploring the possibility of implementing browser automation directly within a web browser using HTML and JavaScript. While Selenium is a well-known option, it does not operate from within the browser itself. My idea is to h ...

Extracting information from a division using Selenium

I am attempting to choose an element for clicking on a page (). The element in question is a date selection within a calendar pop-up. Specifically, the element is: <div class="day unit in-range" data-time="1698822000000">1</d ...

Checking for duplicate entries in an array created with the Angular form builder

I am currently utilizing angular6 reactive form with form builder and form array. The issue I am encountering is duplicate subject entries from the drop down in the form array. How can I implement validation to prevent duplicate entries in the form array? ...

Aligning a div between the page margins with a single click

I am attempting to compile a list of products with a concealed div inside. Upon clicking on the product, the hidden div should reveal and display details. If you inspect the fiddle, you'll notice that the final hidden div protrudes beyond the margins ...

What is the method for adding an event listener in AngularJS within an ng-repeat iteration?

I'm completely new to AngularJS and currently working on building a photo gallery. The basic idea is to have an initial page displaying thumbnail photos from Twitter and Instagram using an AngularJS ng-repeat loop. When a user hovers over an image, I ...

The HTML body is given a right margin for proper spacing

Within the page, I noticed some margin to the right that extends beyond the body itself, causing a scroll bar to appear at the bottom. However, I'm unable to determine the root cause of this issue. I have provided links to both Codepen and Netlify be ...

What is the best way to extend an inline-block element to cover the entire text line?

Let's talk about the scenario: https://i.stack.imgur.com/we05U.png In the image, there is a container (displayed as a div) with only one child - a span element. The goal is to introduce a second child that occupies the entire red space depicted in t ...

Tips for integrating a fully revamped design for social network share buttons

Is it possible to customize social network like buttons similar to the ones shown in the attached image? ...

What is the best way to target and select all spans within a specific div using JavaScript?

I'm struggling with selecting all spans in the card using code that currently only selects the first span when I use getElementsByTagName. Can anyone offer assistance as I have multiple cards containing spans? TypeError: Failed to execute 'inse ...