Creating an overlay effect simply means putting two div together at the same place but both the div appear when needed i.e while hovering or while clicking on one of the div to make the second one appear. Overlays are very clean and give the webpage a tidy look. It looks sophisticated and is simple to design. Overlays can create using two simple CSS properties:
- z-index
- position
Example 1:
<!DOCTYPE html> <html> <head> <title>overlay div</title> <style> .geeks { position: absolute; height: 250px; width: 500px; background-color:green; } .gfg { color:white; padding-top:80px; padding-left:70px; font-size:40px; font-weight:bold; } .g4g { padding-left:95px; } </style> </head> <body> <div class = "geeks"> <div class = "gfg">GeeksforGeeks</div> <div class = "g4g">A computer science portal for geeks</div> </div> </body> </html> |
Output:

Note: Customize the overlay effects by adding more CSS to the page to make it look more elegant.
Example 2:
<!DOCTYPE html> <html> <head> <title>overlay div</title> <style> .geeks { position: absolute; height: 250px; width: 500px; background-color:green; } .gfg { color:white; padding-top:80px; padding-left:70px; font-size:40px; font-weight:bold; } .g4g { padding-left:90px; } .gfg:hover { z-index: -1; opacity: 0.5; font-size:20px; text-align:center; transform-style:all; transition-duration: 1s; } .g4g:hover { z-index: -1; opacity: 0.3; font-size:40px; text-align:center; transform-style:all; transition-duration: 1s; } </style> </head> <body> <div class = "geeks"> <div class = "gfg">GeeksforGeeks</div> <div class = "g4g">A computer science portal for geeks</div> </div> </body> </html> |
Output:
Before hovering:

After hovering:

Recommended Posts:
- How to copy the content of a div into another div using jQuery ?
- How to center a div within another div?
- Display div element on hovering over <a> tag using CSS
- How to Create Image Overlay Hover using HTML & CSS ?
- How to Create an Image Overlay Icon using HTML and CSS ?
- How to Create Full Screen Overlay Navigation Bar using HTML CSS and JavaScript ?
- How to make a glass/blur effect overlay using HTML and CSS ?
- CSS | Combine background image with gradient overlay
- CSS Image overlay hover title
- How to Change Background Color of a Div on Mouse Move Over using JavaScript ?
- How to ignore mouse interaction on overlay image using JavaScript ?
- How to use links on card-img-overlay class in Bootstrap 4 ?
- How to place SVG icons on a round circle side by side to another div using Bootstrap?
- How to override the CSS properties of a class using another CSS class ?
- How to clear all div's content inside a parent div ?
- How to include one CSS file in another?
- How to make the cursor to hand when a user hovers over a list item using CSS?
- How to split text horizontally on mouse move over using CSS ?
- Making a div vertically scrollable using CSS
- How to align content of a div to the bottom using CSS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


