Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Display a blue shadow on image hover with CSS
To display a blue shadow on image hover, use the CSS box-shadow property with the :hover pseudo-class. This creates an interactive effect that enhances user experience by providing visual feedback when users hover over images.
Syntax
selector:hover {
box-shadow: horizontal-offset vertical-offset blur-radius spread-radius color;
}
Example: Blue Shadow on Image Hover
The following example displays a blue shadow when you hover over the image −
<!DOCTYPE html>
<html>
<head>
<style>
img {
width: 250px;
height: 200px;
border: 2px solid orange;
border-radius: 8px;
padding: 10px;
transition: box-shadow 0.3s ease;
cursor: pointer;
}
img:hover {
box-shadow: 0 0 15px 5px blue;
}
</style>
</head>
<body>
<h3>Hover over the image to see the blue shadow effect</h3>
<img src="/css/images/logo.png" alt="TutorialsPoint Logo">
</body>
</html>
An image with an orange border appears on the page. When hovered, a blue shadow with 15px blur and 5px spread appears around the image. The transition creates a smooth animation effect.
Example: Multiple Shadow Colors
You can create multiple shadows with different colors for a more dramatic effect −
<!DOCTYPE html>
<html>
<head>
<style>
.multi-shadow {
width: 200px;
height: 150px;
margin: 20px;
border-radius: 10px;
transition: box-shadow 0.4s ease;
}
.multi-shadow:hover {
box-shadow:
0 0 10px blue,
0 0 20px lightblue,
0 0 30px darkblue;
}
</style>
</head>
<body>
<h3>Multi-layered blue shadow effect</h3>
<img class="multi-shadow" src="/css/images/logo.png" alt="Multi Shadow Example">
</body>
</html>
An image appears with rounded corners. On hover, it displays three layered blue shadows of different intensities and sizes, creating a glowing effect.
Conclusion
The box-shadow property with :hover creates engaging hover effects for images. Adding a transition property ensures smooth animation, making the interaction more polished and professional.
Advertisements
