Darkening Element Background Color with CSS
Enhancing the user interface involves highlighting interactive elements, such as buttons, by altering their appearance. A common approach is to darken the background color upon hover.
Initially, one might attempt to adjust the opacity, but that affects both the color and transparency. A more targeted solution exists.
Method: Overlay a Dark Layer
Create a dark overlay using background-image. This method preserves the original text color while darkening the background.
Implement the overlay layer in CSS:
.Button { background-image: linear-gradient(rgb(0 0 0/40%) 0 0); } .Button:hover { background-color: /* Original background color */; }
This technique automagically darkens any background color, even multiple colors as seen in the example:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3