top of page
Writer's pictureWeb Coding

Shadow effect around an image on hover

Updated: Sep 6, 2020

Learn how to add a shadow around your image when the user hovers over it using only HTML and CSS


HTML

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Document</title>
 <link rel="stylesheet" href="style.css">
</head>
<body>
 <img src="pink-flowers-photograph-1083822.jpg" alt="picture of a flower">
</body>
</html>

CSS

body{
 min-height90vh;
 displayflex;
 align-itemscenter;
 justify-contentcenter;
}

img{
 max-width50%;
 heightauto;
}

img:hover{
 cursorpointer;
 box-shadow0 10px 10px 2px rgba(0000.3),
 10px 0 10px 2px rgba(0000.3),
 0 -10px 10px 2px rgba(0000.3),
 -10px 0px 10px 2px rgba(0000.3)
    ;
}

If you found this blog post helpful don’t forget to check out my other projects and if you want more content follow me on


YouTube: https://www.youtube.com/channel/UC2nxqB2usQIS2c8zwVZKWEQ

Instagram: https://www.instagram.com/coding_for_the_web/

Twitter: https://twitter.com/LearnWebCoding

20 views

Comments


bottom of page