Reveal an image with smart padding (#snippet)

Here’s Temani Afif once again doing what he does best: creating wild single-element tricks. What’s on this time?
The preview below shows the article’s result, which is two image elements.


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Here's Temani Afif once again doing what he does best: creating wild single-element tricks. What's on this time?

The preview below shows the article's result, which is two image elements.

The img elements are displayed as 3D boxes and only reveal their image content when hovering. There are no div wrappers or anything — what you see above are two img elements.

Temani walks you through how to create this effect step by step; go check it out. It's a great read.

But one thing stood out in the article: you might think that the images hide and show with some wild CSS tricks, but the effect uses good ol' padding-right.

Here's a minimal example.

[Interactive component: visit the article to see it...]

By applying full-width padding to the image, the actual image is "pushed out" of the container. The applied object-fit: cover then prevents the image from being squished. And as the cherry on top: if you change object-position from left to right, the revealing effect becomes a "slide in". Go and try it above!

I don't know when and if I'll use this effect, but it's more than worth a snippet entry on this blog. Thank you, Temani!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2024-04-19T22:00:00+00:00) Reveal an image with smart padding (#snippet). Retrieved from https://www.scien.cx/2024/04/19/reveal-an-image-with-smart-padding-snippet/

MLA
" » Reveal an image with smart padding (#snippet)." Stefan Judis | Sciencx - Friday April 19, 2024, https://www.scien.cx/2024/04/19/reveal-an-image-with-smart-padding-snippet/
HARVARD
Stefan Judis | Sciencx Friday April 19, 2024 » Reveal an image with smart padding (#snippet)., viewed ,<https://www.scien.cx/2024/04/19/reveal-an-image-with-smart-padding-snippet/>
VANCOUVER
Stefan Judis | Sciencx - » Reveal an image with smart padding (#snippet). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/04/19/reveal-an-image-with-smart-padding-snippet/
CHICAGO
" » Reveal an image with smart padding (#snippet)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2024/04/19/reveal-an-image-with-smart-padding-snippet/
IEEE
" » Reveal an image with smart padding (#snippet)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2024/04/19/reveal-an-image-with-smart-padding-snippet/. [Accessed: ]
rf:citation
» Reveal an image with smart padding (#snippet) | Stefan Judis | Sciencx | https://www.scien.cx/2024/04/19/reveal-an-image-with-smart-padding-snippet/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.