×

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The design is also quite easy.

Designing an overlay consequence specifies that putting two div elements together at any same place. Though, both the elements will present when required. If we create any second div element that occurs, we can click or hover over one div. One div element is an overlay div and includes what will display if any user hovers on the image. The second div element is any container that holds the images both and also its overlay.

Fade Overlay Effect

This overlay specifies that if we move the point of the cursor over an image, then it will display over the image’s top area. Let’s consider an example, given below:

Example:

<!DOCTYPE html>
<html>
<head>
<title> Image Overlay </title>
<style>
.container img
{
 width: 300px;
 height: 300px;
}
.container
{
 position: relative;
 width: 25%;
 height: auto;
}
.overlay
{
 position: absolute;
 transition: 0.5s ease;
 height: 300px;
 width: 100px;
 top: 0;
 left: 0;
 background-color: violet;
 opacity: 0;
}
.container:hover .overlay
{
 opacity: 0.9;
}
</style>
</head>
<body>
<center>
<h1> Fade Overlay Effect </h1>
<h2> Point the cursor on the image to feel the effect. </h2>
<div class= "container">
<img src= "Flower3.png">
<div class= "overlay"></div>
</div>
</center>
</body>
</html>

Output:

CSS Overlay

Image Overlay Slide

By using the image overlay slide, we can make any effect of sliding overlay with the help of four distinct types like left, right, top, and bottom. We will discuss it with an example.

Overlay Slide from top to bottom

Now, we will understand how to make a slide inside the overlay from any top surface with the help of an example.

Example:

<!DOCTYPE HTML>  
<html>  
<head>  
<style>  
.container img
{  
 width: 300px;  
 height: 300px;  
}  
.container
{  
 position: relative;  
 width: 25%;  
 height: auto;
}   
.container:hover .overlay
{  
 opacity: 0.8;  
 height: 300px;  
}  
.overlay
{  
 position: absolute;  
 transition: 0.7s ease;  
 opacity: 0;  
 width: 100px;  
 height: 0;  
 top: 0;  
 right: 20px;
 left: 0;  
 background-color: violet;  
}  
</style>  
</head>  
<body>  
<center>          
<h1> Overlay slide from top to bottom </h1> 
<h2> Point the cursor on the image to feel the effect. </h2> 
<div class="container">  
<img src= "Flower3.png">  
<div class="overlay"></div>  
</div>  
</center>  
</body>  
</html> 

Output:

CSS Overlay

Overlay Slide from bottom to top

When we point the cursor on any image, it will slide from the bottom to the top. To understand this, let’s assume an example.

Example:

<!DOCTYPE HTML>  
<html>  
<head>  
<style>  
.container img
{  
 width: 300px;  
 height: 300px;  
}  
.container
{  
 position: relative;  
 width: 25%;  
 height: auto;
}   
.container:hover .overlay
{  
 opacity: 0.8;  
 height: 300px;  
}  
.overlay
{  
 position: absolute;  
 transition: 0.7s ease;  
 opacity: 0;  
 width: 100px;  
 height: 0;  
 bottom: 0;  
 right: 20px;
 left: 0;  
 background-color: violet;  
}  
</style>  
</head>  
<body>  
<center>          
<h1> Overlay slide from bottom to top </h1> 
<h2> Point the cursor on the image to feel the effect. </h2> 
<div class="container">  
<img src= "Flower3.png">  
<div class="overlay"></div>  
</div>  
</center>  
</body>  
</html> 

Output:

CSS Overlay

Overlay Slide from left to right

As the name suggests, left to right sliding will be there. See the example below.

Example:

<!DOCTYPE HTML>  
<html>  
<head>  
<style>  
.container img
{  
 width: 300px;  
 height: 300px;  
}  
.container
{  
 position: relative;  
 width: 25%;  
 height: auto; 
}   
.container:hover .overlay
{  
 opacity: 0.8;  
 width: 300px;  
}  
.overlay
{  
 position: absolute;  
 transition: 0.7s ease;  
 opacity: 0;  
 width: 0;  
 height: 100%;  
 bottom: 0;  
 left: 20px;  
 background-color: violet;  
}  
</style>  
</head>  
<body>  
<center>  
<h1> Overlay slide from left to right </h1> 
<h2> Point the cursor on the image to feel the effect. </h2> 
<div class="container">  
<img src= "Flower3.png">  
<div class="overlay"></div>  
</div>  
</center>  
</body>
</html>  

Output:

CSS Overlay

Overlay Slide from right to left

This sliding method is quite similar to various effects, as mentioned above, except that it will slide from the right surface to the left surface.

Example:

<!DOCTYPE HTML>  
<html>  
<head>  
<style>  
.container img
{  
 width: 300px;  
 height: 300px;  
}  
.container
{  
 position: relative;  
 width: 25%;  
 height: auto; 
}   
.container:hover .overlay
{  
 opacity: 0.8;  
 width: 300px;  
}  
.overlay
{  
 position: absolute;  
 transition: 0.7s ease;  
 opacity: 0;  
 width: 0;  
 height: 100%;  
 bottom: 0;  
 right: 20px;  
 background-color: violet;
}  
</style>  
</head>  
<body>  
<center>  
<h1> Overlay slide from right to left </h1> 
<h2> Point the cursor on the image to feel the effect. </h2> 
<div class="container">  
<img src= "Flower3.png">  
<div class="overlay"></div>  
</div>  
</center>  
</body>
</html>  

Output:

CSS Overlay

Image Overlay title

In an image overlay consequence, if we point the cursor on the image, we can see a title over it. Consider the following illustration.

Example:     

<!DOCTYPE HTML>  
<html>  
<head>  
<meta name= "viewport" content= "width=device-width, initial-scale=1"> 
<style>
body
{  
 text-align: center;
}  
* {box-sizing: border-box;}
.container
{  
 position: relative;  
 width: 50%;  
 max-width: 300px;
}   
img
{
 display: block;
 width: 100%;
 height: auto;
}
.overlay
{  
 position: absolute;
 bottom: 0; 
 background: rgba(0, 0, 0, 0.2);
 width: 100%;
 opacity: 0;    
 transition: .9s ease;
 font-size: 25px;  
 padding: 20px;
}  
.container:hover .overlay
{  
 opacity: 1.5; 
}             
</style>  
</head>  
<body>  
<h1> Image Overlay Title Effect </h1> 
<h2> Point the cursor on the image to feel the effect. </h2>
<center>   
<div class= "container">  
<img src= "flower.png">  
<div class= "overlay"> Welcome to this Page </div>  
</div>  
</center>  
</body>
</html>  

Output:

CSS Overlay

Image Overlay icon

In this effect of the overlay, an icon over the mouse hovering will be there to cover the whole image. We will also set a link over the icon to swap between any pages. Consider the following illustration given below:

Example:

<!DOCTYPE HTML>  
<html>  
<head>  
<meta name= "viewport" content= "width=device-width, initial-scale=1"> 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> 
<style>
.container
{  
 position: relative;  
 width: 100%;  
 max-width: 400px;
}   
.img
{
 display: block;
 width: 100%;
 height: auto;
}
.overlay
{  
 position: absolute;
 top: 0; 
 height: 100%; 
 width: 100%; 
 opacity: 0; 
 transition: 1s ease; 
 background-color: violet;  
}  
.container:hover .overlay
{  
 opacity: 1; 
}      
.icon
{
 color: blue;
 font-size: 100px;
 position: absolute;
 top: 50%;
 left: 50%;
 transform: translate(-50%, -50%);
}      
</style>  
</head>  
<body>  
<center>         
<h1> Image Overlay icon Effect </h1> 
<h2> Point the cursor on the image to feel the effect. </h2>   
<div class= "container">  
<img src= "Flower3.png" class= "img">  
<div class= "overlay">
<a href= "#" class= "icon">
<i class= "fa fa-home"></i>
</a>
</div>  
</div>  
</center>  
</body>
</html>  

Output:

CSS Overlay

Related Topics

CSS Filter

CSS Filter CSS filter is used to apply visual effects on the images, text, and other factors of the webpage. This filter property in CSS allows us to admit the effects like...

7 minutes read.

CSS 3D Transform

Introduction To understand 3D transformation property of transform you need to first understand the difference between 2D and 3D transform. 2D transform is a CSS effect which transforms the elements according to...

6 minutes read.

CSS Padding

CSS Padding: The padding property in CSS is addressed to describe the space among the element border and the element content.This property is quite different from the margin property of...

2 minutes read.

CSS Pseudo-class

Pseudo-class The pseudo-class may be depicted as the keyword which can be mixed to any selector that specifies the elected element’s unique state. It can be included to a selector to...

6 minutes read.

CSS Pseudo-elements

Pseudo-elements The pseudo-classes in CSS can be represented as any keyword which is connected to the selector that represents any selected element’s unique state. On the other hand, pseudo-elements can be...

6 minutes read.

Is CSS a programming language?

 A programming language is a set of grammatical rules and a vocabulary for commanding a machine to accomplish specified tasks. High-level languages like BASIC, C, C++, COBOL, Java, FORTRAN, Ada...

4 minutes read.

CSS Reference

The CSS Reference lists all of the basic standard CSS properties, pseudo-classes, pseudo-elements, and data types, for all intents and purposes functional notations, and at-rules alphabetically.  The site also includes...

5 minutes read.

Divi in CSS

Divi is popular WordPress themes due to its versatility and user-friendly interface. It includes a built-in page builder for sophisticated design options and an assortment of customization features to help...

9 minutes read.

CSS Text-decoration

CSS Text-decoration: It is an essential property of CSS that is used to decorate the content of the text. It can add-on the lines above, under, and over the text....

3 minutes read.

CSS Functions

CSS functions are used for different CSS properties. Every front-end developer should have knowledge of all CSS functions. It makes the coding easier. FunctionsExplanationattr().It returns the value of an attribute of...

5 minutes read.

CSS Tutorial

CSS refers to the Cascading Style Sheet. CSS is a form of a programming language. In other words, CSS is a language of the style sheet that is utilised for...

9 minutes read.

CSS Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 minutes read.

CSS Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

2 minutes read.

CSS Page-break-after Attribute

Page-break-after Attribute As its name implies, the page-break-before property is applied to include page break after any element, at the time of printing a document. It adds the page break after...

5 minutes read.

CSS Width

CSS Width The width property in CSS sets the content width of area of the element. These properties do not provide margin and border features. It is used to set the...

1 minute read.

CSS Animation

CSS Animation: The animation property of CSS is applied to make animation over any webpage. It is used as the animation replacement made by JavaScript and Flash. Rules of CSS3 @keyframes The...

3 minutes read.

CSS Selector

CSS Selector: There are some selectors used in CSS, which allows us to choose the content we wish to style. Various selectors are considered as the separation of the set...

5 minutes read.

How to resize an image in CSS

How to resize an image in CSS? The resize image attribute is used in responsive web design to resize images to fit within the div container automatically. The resize image attribute...

3 minutes read.

Internal CSS

What is CSS? CSS stands for Cascading Style Sheet.CSS is used to apply styling the HTML elements.With CSS user can add or change color, font-size and font-family. It also helps user...

4 minutes read.

CSS Comments

CSS Comments: Generally, comments in CSS are used to describe our code. Further, it will provide support to many users who are concerned with the code. Somewhat, these are ignored...

2 minutes read.