Create a CSS-Only Image Reveal Effect with Transparent Borders

A CSS-only picture exhibit effect can be solved in opposite ways. It’s indeed utterly easy to formula a pattern in that a image stands out of (is overflown by) its plain background —you usually place an image over a smaller component with a plain background.

You can get a same outcome if we use transparent borders, where we keep a size of a credentials component a same as that of a forehead and supplement pure borders in sequence to create an dull space for a forehead to crawl into.

How to Create a Cut-out Border Design with CSS

With a cut-out limit pattern we can uncover to users what can be found underneath a limit area…Read more

There are some advantages in regulating a latter method. Since it’s a pure borders that yield a area for a forehead to crawl into, we can control a instruction of a overflow between a left, right, tip and bottom borders. Also, carrying a same distance for both a forehead and a credentials makes it easier to pierce both elements simultaneously opposite a page.

In a nutshell, we’re going to see how to create a CSS-only picture exhibit effect regulating a smaller plain background with a foreground picture that has pure borders. You can check out a final demo below.

1. Create a initial code

HTML-wise, only one div is required:

div class=foo/div

In a CSS, we use two CSS variables, --bgc and --dim for a background colour and a dimensions of a .foo container, respectively. In a example, we used a same value for a breadth and tallness to get a square-shaped box, emanate separate variables for a tallness and a breadth if we wish a rectangular.

The .foo element, a dual pseudo-elements, .foo::before, .foo::after, and their :hover pseudo-classes get a transition property that will add an ease-in transition to them for 500 milliseconds (half a second).

Understanding Pseudo-Element :before and :after

Cascading Style Sheet (CSS) is essentially dictated for requesting styles to a HTML markup, however in some cases…Read more

2. Add a image

We supplement a picture to a .foo::before pseudo-element as a credentials image, and size it to cover a whole pseudo-element with a width and height properties. We stack it right underneath a .foo element regulating a z-index: -1 rule.

Bonus: Optional margin

If we arrangement .foonext to other elements on a page and wish these other elements to move away when a picture and a credentials slides out, afterwards add a right
domain of a same breadth as that of .foo to a .foo:hover element.

All the Graphics on this blog are not our property nor any Image is under our Copyrights.All the graphics have been taken from different sources. If any Graphic/Image is offensive or under your Copyrights please E-mail us to get it removed with in 24 hours.