Steps for adding hover color to a div with linear gradient border

My current challenge involves adding a hover color to a specific div, but I'm facing obstacles due to the gradient background that was implemented to achieve border-radius functionality.

This task is being carried out within a React Component using css-modules.

I am not a CSS expert and would appreciate insight into the root cause of the issue and possible solutions.

.card{
  width: 40%;
  height: 150px;
  border: 2px solid transparent;
  background:
    linear-gradient(#fff,#fff) padding-box,
    linear-gradient(125deg, #42E4A3, #A383E8) border-box;
  border-radius:8px;
  display:inline-block;
}

.card:hover{
  background-color: rgba(0,0,0,0.04);
}
<div class="card">
  No Hover color red <br/>
  I am doing this in React a small gist of the problem
</div>

Update

Upon implementing the specified styles, I encountered an unexpected outcome where the border gradient color shows up on hover. Adding certain changes results in the appearance of the color, but causes the border color to disappear.

The gradient seems to have restrictions when it comes to accepting low-opacity rgba values. I'm curious to understand why.

.card:hover{
  background:
    linear-gradient(rgba(0,0,0,0.04),rgba(0,0,0,0.04)) padding-box;
} // no border color , when i change the color to rgba opacity it dosent work 

rgba(0,0,0,0.1) works but why not rgba(0,0,0,0.04)

Answer №1

To enhance your hover effect, consider updating the background property in your :hover style by replacing the white color #fff with a vibrant color like red.

.card{
  width: 40%;
  height: 150px;
  border: 2px solid transparent;
  background:
    linear-gradient(#fff,#fff) padding-box,
    linear-gradient(125deg, #42E4A3, #A383E8) border-box;
  border-radius:8px;
  display:inline-block;
}

.card:hover{
  background:
    linear-gradient(red,red) padding-box,
    linear-gradient(125deg, #42E4A3, #A383E8) border-box;
}
<div class="card">
  No Hover color red <br/>
  I am doing this in React a small gist of the problem
</div>

Answer №2

If you are looking to make some adjustments, you can try this method:

.card:hover{
  background: red;
}

By implementing the above code snippet, you should see the desired effect.

Alternatively, if you prefer to maintain a gradient border:

.card:hover{
      background: linear-gradient(red,red) padding-box, 
                  linear-gradient(125deg, #42E4A3, #A383E8) border-box;
    }

In case you want a slightly transparent background color, you may need to modify your solution like in this Codepen demo. However, please note that there might still be some visibility of the underlying content due to the partial transparency on hover.

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

ReactJS custom theme switch functionality is not functioning as intended

I am currently working with three different custom themes and I am looking to seamlessly switch between them. However, I have encountered some issues that I need help with: Why is the container from CustomToolbar.jsx functioning correctly, but not the co ...

encountering difficulties while trying to install packages using npm

I encountered some issues while setting up a react-app and attempted to resolve them by deleting /node-modules and reinstalling, but the problems persist. I'm using Ubuntu as my operating system. Can someone assist me with this? Below is the error log ...

Customize nestjs/crud response

For this particular project, I am utilizing the Nest framework along with the nestjs/crud library. Unfortunately, I have encountered an issue where I am unable to override the createOneBase function in order to return a personalized response for a person e ...

What is the best way to implement a side navigation bar with 100 tabs using Angular 4?

I am new to learning AngularJS and could use some guidance. Currently, I am working on an Angular 4 SPA project that consists of a sidebar with 100 tabs, each containing different content. Here is an image of the sidebar. I have tried a simple approach by ...

Tips for building a versatile client-server application with separate codebases for the JavaScript components

We are embarking on the process of rebuilding our CMS and leveraging our expertise with VueJS. Despite our familiarity with VueJS, we won't be able to create a full single-page application due to the presence of server-side rendering files (JSP). The ...

I want to create a feature where a video will automatically play when a user clicks on a specific item in a list using Angular

Currently, I'm working on a project that involves displaying a list of videos and allowing users to play them in their browser upon clicking. The technology stack being used is Angular 2. Below is the HTML code snippet for achieving this functionalit ...

Elements within the div are overlapping each other

Despite adding margin, my h3 tag and p tag in a div keep overlapping. .title { margin: 0 0 26px; width: 335px; height: 28px; font-size: 24px; font-stretch: normal; font-style: normal; line-height: 36px; letter-spacing: 0; text-align: c ...

How can I prevent my code from resetting every time a state update occurs?

I've coded a program that creates a 10x10 grid with 5 boxes of varying sizes. When you click on a box, an x is added to its content and the turn state is set to false. The issue arises when the code re-runs after each state update, causing the 5 rand ...

`AWS EC2 deployment of PERN stack encountering Nginx URL complication`

Seeking assistance or guidance with my current issue would be greatly appreciated. Everything functions correctly on localhost, but upon deploying to AWS, the Axios request URLs for sub-pages become formatted incorrectly. It seems there may be an issue wi ...

Steps for effectively incorporating the useEffect hook in your code

It's no surprise that there are numerous questions addressing this issue, but each situation is unique and heavily context-dependent. Applying solutions from others to my own problem in a large React application with complex state has proven to be a c ...

Prevent elements from overlapping within a flexbox container

I've encountered an issue with resizing the window causing the logos to overlap the portrait image. Is there a way to fix the logos relative to the portrait? Below is the code: /* Defaults for Main Part of Pages */ body, div, h1, p { margin: 0; ...

difficulty in making an https request

My application was developed using OFFICEjs and was functioning properly on LOCALHOST. However, last week it suddenly started throwing an error message - "XHR Error." This issue arose out of nowhere, as I hadn't made any changes to the code over the w ...

Leveraging LESS variables within media queries

After inputting the less code below into : @item-width: 120px; @num-cols: 3; @margins: 2 * 20px; @layout-max-width: @num-cols * @item-width + @margins; @media (min-width: @layout-max-width) { .list { width: @layout-max-width; } } The resul ...

Incorporate keyframe animation into a styled component in material-ui using React

Currently seeking assistance with implementing key frames animation using react material-ui(version ^5.0.0). I am using styled components to style my JSX elements, but encountering errors when trying to incorporate keyframes animation within these styled c ...

Error encountered in Angular $injector:unpr while attempting to initialize uibModal

I followed the ui-bootstrap tutorial to create my code. On my homepage, there is a button that triggers a modal window to open using ng-click. However, when I check the dev tools, I encounter the following error: Error: [$injector:unpr] Unknown provider: ...

Switch the position of the Refer a friend button and the name button to the right

I am seeking assistance to align two buttons to the right. const getFullName = () => { if (authContext.user.first_name) { return `${authContext.user.first_name} ${authContext.user.last_name}`; } return authContext.use ...

What can be done to stop a header from sticking to a table and displaying horizontally scrolling content along the border?

I need to ensure that the red headers do not overlap with the blue headers' borders while scrolling horizontally. It is essential for me to have a white border on the blue headers. .container { overflow: auto; width: 200px; } table { borde ...

Expanding a class functionality by incorporating a method through .prototype

My goal is to define a class called "User" and then add a method to the class using the "prototype" keyword. I want the method "who_auto" to be accessible to all future instances of "User". When testing this code in JSFiddle, I encountered the error messa ...

What could be causing the error message to appear stating that each list item must have a unique key when utilizing react-bootstrap in Nextjs?

My file currently contains keys for each child component, but it is still raising an error internally. I am unsure if I can resolve these issues on my own. export default function SecondaryNav(props:NavItems) { const router = us ...

Using jQuery for validation using a checkbox

I'm currently working on a registration system that allows users to choose between paying immediately with a credit card or later with a check. Depending on their choice, the fields for credit card information should either be validated or hidden to d ...