Using:hover pseudo-class In HTML
In this approach, we are using the:hover pseudo-class in CSS to define a shadow effect for a button when it is hovered over. The box-shadow property is applied with specified values.
Syntax:
button:hover {
box-shadow: x y z rgb(a, b, c);
}
where x= 8px , y= 8px , z= 9px , a= 0 , b= 255 , c= 0 .
Example: The below example uses:hover pseudo class to add a shadow to a Button.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
<title>pseudo class</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
background-color: #f8f8f8;
color: #333;
}
h1 {
color: #4CAF50;
}
h3 {
margin-bottom: 20px;
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #007BFF;
color: #fff;
border: none;
cursor: pointer;
transition: box-shadow 0.3s;
}
button:hover {
box-shadow: 8px 8px 9px rgb(0, 255, 0);
}
</style>
</head>
<body>
<h1>w3wiki</h1>
<h3>Using :hover pseudo class</h3>
<button>Click me</button>
</body>
</html>
Output:
How to Add a Shadow to a Button ?
Adding a shadow to the button significantly enhances the visual appeal of the elements, improving the overall look and feel of the application. We can add a Shadow to a Button using different approaches including, the box-shadow property, CSS variables, filter property, and pseudo-class.
We can use these approaches to add a shadow to the button:
Table of Content
- Using box-shadow Property
- Using CSS Variables
- Using filter property
- Using :hover pseudo class