Created
February 24, 2015 15:48
-
-
Save beije/7ce5c54bf866d2ffebb1 to your computer and use it in GitHub Desktop.
Vignetting an image in CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="image-container"> | |
<img src="myimage.jpg" /> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.image-container { | |
width: 640px; | |
position: relative; | |
/* Remove the parts of the circle that is outside of the image */ | |
overflow: hidden; | |
} | |
.image-container:after { | |
content: ''; | |
position: absolute; | |
/* Center element on the middle of it's parent */ | |
top: 50%; | |
left: 50%; | |
/* Reset back the image so it's center is locked on the center of the parent */ | |
transform: translate(-50%,-50%); | |
/* Only set the width of the image */ | |
width: 120%; | |
/* Using the padding trick, we force the elments padding bottom to push down the height */ | |
/* To form a square, the padding-bottom, needs to have the same value as the width property */ | |
padding-bottom: 120%; | |
box-shadow: inset 0px 0px 150px 60px rgba(0,0,0,0.8); | |
border-radius: 50%; | |
} | |
.image-container img { | |
max-width: 100%; | |
display: block; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment