CSS Image Overlay Zoom

Please Share On:

Definition:

Here, you are going to learn how to create an image overlay zoon effect on mouse hover.

Let’s begin our design.

First, create a simple <html> code without any CSS code.

For this, you need an image and an overlay text. Make an HTML container and put your image and text in it.

HTML Source Code:

<h3 class="title">Image Overlay Zoom</h3> 
      <div class = "container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="CSS Image Overlay Zoom" class="image">
        
        <div class="overlay">
    		<div class="text">This is a Opera House.</div>
  		</div>
      </div> 

CSS Source Code:

<style>
    .container {
         position: relative;
         width: 50%;
      }
      
       .image {
        display:block;
        width: 100%;
        height: auto;
        opacity: 1;
        transition: .5s ease;
      }
      
      .overlay {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: #008CBA;
        overflow: hidden;
        width: 100%;
        height: 100%;
        transform: scale(0);
        transition: .3s ease;     
	  }
      
      .container:hover .overlay {
 		 transform: scale(1);
	   }
      
      .container:hover .overlay-box
      {
        opacity: 1;
 	  }
      
      .text{    
        background-color: black;
        color: white;
        font-size: 20px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        text-align: center;  
        padding: 10px 15px;
      }
      
    </style>

Full Source Code:

<!DOCTYPE html>
<html>
  <head>
    <style>
    .container {
         position: relative;
         width: 50%;
      }
      
       .image {
        display:block;
        width: 100%;
        height: auto;
        opacity: 1;
        transition: .5s ease;
      }
      
      .overlay {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        background-color: #008CBA;
        overflow: hidden;
        width: 100%;
        height: 100%;
        transform: scale(0);
        transition: .3s ease;     
	  }
      
      .container:hover .overlay {
 		 transform: scale(1);
	   }
      
      .container:hover .overlay-box
      {
        opacity: 1;
 	  }
      
      .text{    
        background-color: black;
        color: white;
        font-size: 20px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        text-align: center;  
        padding: 10px 15px;
      }
      
    </style>
 
  </head>
  
  <body> 
      <h3 class="title">Image Overlay Zoom</h3> 
      <div class = "container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="CSS Image Overlay Zoom" class="image">
        
        <div class="overlay">
    		<div class="text">This is a Opera House.</div>
  		</div>
      </div>    
  </body>
</html>																
					

Output:

Image Overlay Zoom

CSS Image Overlay Zoom
This is a Opera House.

Donate to support writers.


You may be interested in the following topics:

CSS Image Overlay Icon

Please Share On:

Definition:

Here, you are going to learn how an icon will appear over an image when you hover your mouse cursor over the image.

Let’s begin our design.

First, create a simple <html> code without any CSS code.

For this, you need an image and an icon. Make an HTML container and put your image and an icon in it.

You can use font Awesome icons and define a link in your HTML code before using it. See an example below:

HTML Source Code:

<meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.7/css/all.css">    

<div class="container">
      <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="Image Overlay Text" class="image">
      <div class="overlay">
     <a href="#" class="icon" title="thumbs-up">
      <i class="fa fa-thumbs-up" aria-hidden="true"></i>
    </a>
</div>
    </div>

CSS Source Code:

<style>
    .container {
      position: relative;
      width: 100%;
      max-width: 400px;
    }

    .image {
      display: block;
      width: 100%;
      height: auto;
    }

    .overlay {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      height: 100%;
      width: 100%;
      opacity: 0;
      transition: .3s ease;
    }

    .container:hover .overlay {
      opacity: 0.5;
    }

    .icon {
      background: white;
      font-size: 100px;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      -ms-transform: translate(-50%, -50%);
      text-align: center;
    }
    </style>

Full Source Code:

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.7/css/all.css">
    <style>
    .container {
      position: relative;
      width: 100%;
      max-width: 400px;
    }

    .image {
      display: block;
      width: 100%;
      height: auto;
    }

    .overlay {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      height: 100%;
      width: 100%;
      opacity: 0;
      transition: .3s ease;
    }

    .container:hover .overlay {
      opacity: 0.5;
    }

    .icon {
      background: white;
      font-size: 100px;
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      -ms-transform: translate(-50%, -50%);
      text-align: center;
    }
    </style>
 
  </head>
  
  <body> 
        <div class="container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="Image Overlay Text" class="image">
          <div class="overlay">
           <a href="#" class="icon" title="thumbs-up">
            <i class="fa fa-thumbs-up" aria-hidden="true"></i>
          </a>
			</div>
    	</div>  
  </body>
</html>																
					

Output:


Donate to support writers.


You may be interested in the following topics:

CSS Image Overlay Title

Please Share On:

Definition:

Here, you are going to learn how a title will appear over an image when you hover your mouse cursor over the image.

Let’s begin our design.

First, create a simple <html> code without any CSS code.

For this, you need an image and a title of the text. Make an HTML container and put your image and title in it.

HTML Source Code:

    <div class="container">
      <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="Image Overlay Text" class="image">
      <div class="overlay">This is Opera House</div>
    </div>

CSS Source Code:

<style>
      .container {
        position: relative;
        width: 100%;
        max-width: 500px;
      }

      .image {
        display:block;
        width: 100%;
        height: auto;
        opacity:1;
      }

      .overlay {
        position: absolute; 
        bottom: 0; 
        background: rgb(0, 0, 0);
        background: rgba(0, 0, 0, 0.5);
        color: #f1f1f1; 
        width: 90%;
        transition: .5s ease;
        opacity:0;
        color: white;
        font-size: 20px;
        padding: 20px;
        text-align: center;
      }

      .container:hover .overlay {
        opacity:1;
      }
      
    </style>

Full Source Code:

<!DOCTYPE html>
<html>
  <head>
    <style>
      .container {
        position: relative;
        width: 100%;
        max-width: 500px;
      }

      .image {
        display:block;
        width: 100%;
        height: auto;
        opacity:1;
      }

      .overlay {
        position: absolute; 
        bottom: 0; 
        background: rgb(0, 0, 0);
        background: rgba(0, 0, 0, 0.5);
        color: #f1f1f1; 
        width: 100%;
        transition: .5s ease;
        opacity:0;
        color: white;
        font-size: 20px;
        padding: 20px;
        text-align: center;
      }

      .container:hover .overlay {
        opacity:1;
      }
      
    </style>
  </head> 

  <body> 
    <h3 class="title">Image Overlay Title</h3>

    <div class="container">
      <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="Image Overlay Title" class="image">
      <div class="overlay">This is Opera House</div>
    </div>    
  </body>
</html>															
					

Output:

Image Overlay Title

Image Overlay Title
This is Opera House

Donate to support writers.


You may be interested in the following topics:

CSS Image Hover Overlay Slide from the right

Please Share On:

Definition:

Here, I am going to show how you can give an image slide effect from the topbottomleft, and right sides.

Let’s first start the Image hover slide effect from the right.

Our task to complete is, whenever we put our mouse over an image, the image shows a sliding effect that travels from right to left and displays some user-choice text. Here I will just display the text “Slide from the right”.

Here is an example we are going to design. Put your mouse cursor over the below image.

CSS Image Hover Overlay Slide from the right
Slide from the right

Let’s begin our design.

First, create a simple <html> code without any CSS code.

<!DOCTYPE html>
<html>
  <head>
 
  </head>
  
   <body> 
      <h3 class="title">Image Hover Overlay Slide From The Right</h3> 
      <div class="container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="CSS Image Hover Overlay Slide from the right" class="image">
        
        <div class="overlay-right-slide">
    		<div class="text">Slide from the right</div>
  		</div>
      </div>    
  </body>
</html>															
					

Output:



Now, style your container and image. Make sure you keep your container position relative and container width will be your design requirement. Here, I have given 50%. You can give 10%, 20%, 100%, or your chosen size.

.container {
         position: relative;
         width: 50%;
      }

Now, we need to design the image with an opacity defined as 1. The opacity will only change as the mouse hovers over the image. Initial opacity will remain at 1 which means your image shows in full transparency.

Make your width 100 percent which covers all your container size and height remains auto. Add the below code to your style sheet.

.image {
        display:block;
        width: 100%;
        height: auto;
        opacity: 1; 
      }

Output:

Your output still looks the same as before.



Now, it’s time to design your overlay. The overlay must be the same size as your image and in an absolute position and at the center of the image. Now, add the below code to your style sheet.

.overlay-right-slide {
        position: absolute;     
        opacity:0;
        bottom: 0;
 	    left: 100%;
        right: 0;
        width: 0;
  		height: 100%;
        overflow: hidden;
        transition: .5s ease;
        background-color: blue;
	  }

Output:

Your output looks like this:

The text “Slide from the right” is hidden behind the main image

Now apply the hover effect on the image and overlay. Add the below code to your style sheets.

.container:hover .image {
 		 opacity:0.7;
	   }
      
      .container:hover .overlay-bottom-slide
      {
        top: 0;
        height: 100%;
        opacity:0.5;
 	  }

Output:

Now, the output looks like the below:

Image Hover Overlay Slide From The Right

CSS Image Hover Overlay Slide from the right
Slide from the right

Now, it is time to design your text, put your text in the absolute center with white color text.

Add the below code to your style sheet

.text{       
        color: white;
        font-size: 14px;
        padding: 10px 15px;  
        text-align: center;
        position:absolute;
        top:50%;
        left:50%;
        transform: translate(-50%, -50%);
        -ms-transform: translate(-50%, -50%);
      }

Now, See your final result by clicking the below “TRY IT YOURSELF” button.


Donate to support writers.


You may be interested in the following topics:

CSS Image Hover Overlay Slide from the left

Please Share On:

Definition:

Here, I am going to show how you can give an image slide effect from the topbottomleft, and right sides.

Lets first start of the Image hover slide effect from the left.

Our task to complete is, whenever we put our mouse over an image, the image shows a sliding effect that travels from left to right and displays some user-choice text. Here I will just display the text “Slide from the left”.

Here is an example we are going to design. Put your mouse cursor over the below image.

CSS Image Hover Fade In A Box
Slide from the left

Let’s begin our design.

First, create a simple <html> code without any CSS code.

<!DOCTYPE html>
<html>
  <head>
 
  </head>
  
   <body> 
      <h3 class="title">Image Hover Overlay Slide From The Left</h3> 
      <div class="container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="Image Hover Overlay Slide From The Left" class="image">
        
        <div class="overlay-left-slide">
    		<div class="text">Slide from the left</div>
  		</div>
      </div>    
  </body>
</html>															
					

Output:

CSS Image Hover Overlay Slide from the left



Now, style your container and image. Make sure you keep your container position relative and container width will be your design requirement. Here, I have given 50%. You can give 10%, 20%, 100%, or your chosen size.

.container {
         position: relative;
         width: 50%;
      }

Now, we need to design the image with an opacity defined as 1. The opacity will only change as the mouse hovers over the image. Initial opacity will remain at 1 which means your image shows in full transparency.

Make your width 100 percent which covers all your container size and height remains auto. Add the below code to your style sheet.

.image {
        display:block;
        width: 100%;
        height: auto;
        opacity: 1; 
      }

Output:

Your output still looks the same as before.



Now, it’s time to design your overlay. The overlay must be the same size as your image and in an absolute position and at the center of the image. Now, add the below code to your style sheet.

.overlay-left-slide {
        position: absolute;     
        opacity:0;
        bottom: 0;
 	right: 100%;
        left: 0;
        width: 0;
        height: 100%;
        overflow: hidden;
        transition: .5s ease;
        background-color: blue;
	  }

Output:

Your output looks like this:

The text “Slide from the left” is hidden behind the main image

Now apply the hover effect on the image and overlay. Add the below code to your style sheets.

.container:hover .image {
 		 opacity:0.7;
	   }
      
      .container:hover .overlay-bottom-slide
      {
        top: 0;
        height: 100%;
        opacity:0.5;
 	  }

Output:

Now, the output looks like the below:

Image Hover Overlay Slide From The Left

Image Hover Overlay Slide From The Left
Slide from the left

Now, it is time to design your text, put your text in the absolute center with white color text.

Add the below code to your style sheet

.text{       
        color: white;
        font-size: 14px;
        padding: 10px 15px;  
        text-align: center;
        position:absolute;
        top:50%;
        left:50%;
        transform: translate(-50%, -50%);
        -ms-transform: translate(-50%, -50%);
      }

Now, See your final result by clicking the below “TRY IT YOURSELF” button.


Donate to support writers.


You may be interested in the following topics:

CSS Image Hover Overlay Slide from the bottom

Please Share On:

Definition:

Here, I am going to show how you can give an image slide effect from the topbottomleft, and right sides.

Let’s first start with the Image hover slide effect from the bottom.

Our task to complete is, whenever we put our mouse over an image, the image shows a sliding effect that travels from bottom to top and displays some user-choice text. Here I will just display the text “Slide from the bottom”.

Here is an example we are going to design. Put your mouse cursor over the below image.

CSS Image Hover Fade In A Box
Slide from the bottom

Let’s begin our designing.

First, create a simple <html> code without any CSS code.

<!DOCTYPE html>
<html>
  <head>
 
  </head>
  
   <body> 
      <h3 class="title">Image Hover Overlay Slide From The Bottom</h3> 
      <div class="container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="Image Hover Overlay Slide From The Bottom" class="image">
        
        <div class="overlay-bottom-slide">
    		<div class="text">Slide from the bottom</div>
  		</div>
      </div>    
  </body>
</html>															
					

Output:

Image Hover Overlay Slide From The Bottom



Now, style your container and image. Make sure you keep your container position relative and container width will be your design requirement. Here, I have given 50%. You can give 10%, 20%, 100%, or your chosen size.

.container {
         position: relative;
         width: 50%;
      }

Now, we need to design the image with an opacity defined as 1. The opacity will only change as the mouse hovers over the image. Initial opacity will remain at 1 which means your image shows in full transparency.

Make your width 100 percent which covers all your container size and height remains auto. Add the below code to your style sheet.

.image {
        display:block;
        width: 100%;
        height: auto;
        opacity: 1; 
      }

Output:

Your output still looks the same as before.



Now, it’s time to design your overlay. The overlay must be the same size as your image and in an absolute position and at the center of the image. Now, add the below code to your style sheet.

.overlay-bottom-slide {
        position: absolute;     
        opacity:0;
        bottom:0;
        right:0;
        top:100%;
        height:0;
  	width:100%;
        overflow: hidden;
        transition: .5s ease;
        background-color: blue;
	  }

Output:

Your output looks like this:

Slide From the bottom
The text “Slide from the bottom” is hidden behind the main image

Now apply the hover effect on the image and overlay. Add the below code to your style sheets.

.container:hover .image {
 		 opacity:0.7;
	   }
      
      .container:hover .overlay-bottom-slide
      {
        top: 0;
        height: 100%;
        opacity:0.5;
 	  }

Output:

Now, the output looks like the below:

Image Hover Overlay Slide From The Bottom

CSS Image Hover Fade In A Box
Slide from the bottom

Now, it is time to design your text, put your text in the absolute center with white color text.

Add the below code to your style sheet

.text{       
        color: white;
        font-size: 14px;
        padding: 10px 15px;  
        text-align: center;
        position:absolute;
        top:50%;
        left:50%;
        transform: translate(-50%, -50%);
        -ms-transform: translate(-50%, -50%);
      }

Now, See your final result by clicking the below “TRY IT YOURSELF” button.


Donate to support writers.


You may be interested in the following topics:

CSS Image Hover Overlay Slide from the top

Please Share On:

Definition:

Here, I am going to show how you can give an image slide effect from the topbottomleft, and right sides.

Let’s first start the Image hover slide effect from the top.

Our task to complete is, whenever we put our mouse over an image, the image shows a sliding effect that travels from top to bottom and displays some user-choice text. Here I will just display the text “Slide from the top”.

Here is an example we are going to design. Put your mouse cursor over the below image.

CSS Image Hover Fade In A Box
Slide from the top

Let’s begin our design.

First, create a simple <html> code without any CSS code.

<!DOCTYPE html>
<html>
  <head>
 
  </head>
  
   <body> 
      <h3 class="title">Image Hover Overlay Slide From The Top</h3> 
      <div class="container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="Image Hover Overlay Slide From The Top" class="image">
        
        <div class="overlay-top-slide">
    		<div class="text">Slide from the top</div>
  		</div>
      </div>    
  </body>
</html>															
					

Output:

Image Hover Overlay Slide Fromt The Top



Now, style your container and image. Make sure you keep your container position relative and container width will be your design requirement. Here, I have given 50%. You can give 10%, 20%, 100%, or your chosen size.

.container {
         position: relative;
         width: 50%;
      }

Now, we need to design the image with an opacity defined as 1. The opacity will only change as the mouse hovers over the image. Initial opacity will remain at 1 which means your image shows in full transparency.

Make your width 100 percent which covers all your container size and height remains auto. Add the below code to your style sheet.

.image {
        display:block;
        width: 100%;
        height: auto;
        opacity: 1; 
      }

Output:

Your output still looks the same as before.



Now, it’s time to design your overlay. The overlay must be the same size as your image and in an absolute position and at the center of the image. Now, add the below code to your style sheet.

.overlay-top-slide {
        position: absolute;     
        opacity:0; /*keep overlay invisible initially*/
        top:0;
        right:0;
        bottom:100%;
        height:0;
        width:100%;    
        transition: .5s ease;
        background-color: blue;
      }

Output:

Your output looks like this:

The Text “Slide from the top” is hidden in the background

Now apply the hover effect on the image and overlay. Add the below code to your style sheets.

.container:hover .image {
        opacity:0.7;
      }

      .container:hover .overlay-top-slide
      {
        bottom: 0;
        height: 100%;
        opacity:0.5;
      }

Output:

Now, the output looks like the below:

Image Hover Overlay Slide From The Top

CSS Image Hover Fade In A Box
Slide from the top

Now, it is time to design your text, put your text in the absolute center with white color text.

Add the below code to your style sheet

.text{       
        color: white;
        font-size: 14px;
        padding: 10px 15px;  
        text-align: center;
        position:absolute;
        top:50%;
        left:50%;
        transform: translate(-50%, -50%);
        -ms-transform: translate(-50%, -50%);
      }

Now, See your final result by clicking the below “TRY IT YOURSELF” button.


Donate to support writers.


You may be interested in the following topics:

CSS Image Hover Overlay Fade In A Box

Please Share On:

Definition:

To display the overlay fade in a box on mouse hover, we begin to design the code from the beginning.

Our task here is, first of all, we create a container and put an image inside that container, create an overlay, and put text inside it. When we hover over the image the image should fade out 50% and the text should fade in 100% and display in a box. Initially, the text should be invisible and visible only on mouse hover on the image as below example.

CSS Image Hover Fade In A Box
Fade In A Box

First, create a simple <html> code.

<!DOCTYPE html>
<html>
  <head>
 
  </head>
  
   <body> 
      <h3 class="title">Fade In A Box</h3> 
      <div class = "container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="CSS Image Hover Fade In A Box" class="image">
        
        <div class="overlay-box">
    		<div class="text">Fade In A Box</div>
  		</div>
      </div>    
  </body>
</html>															
					

Output:



Now, style your container and image. Make sure you keep your container position relative and container width will be your design requirements. Here, I have given 50%. You can give 10%, 20%, 100% or your chosen position.

.container {
         position: relative;
         width: 50%;
      }

Now, we need to design the image with an opacity defined 1. The opacity will only change on the mouse. Initial opacity will remain 1 which means your image shows in full transparency. Add the below code to your style sheet.

.image {
        display:block;
        width: 100%;
        height: auto;
        opacity: 1;
        transition: .5s ease;
      }

Output:

Your output still looks like the same as before.



Now, it’s time to design your overlay. The overlay must be the same size as your image and in an absolute position and at the center of the image. Now, add the below code to your style sheet.

.overlay-box {
        position: absolute;     
      
        /*the below code brings your overlay to center*/
        top: 50%;
        left: 50%;
  	transform: translate(-50%, -50%);
  	-ms-transform: translate(-50%, -50%)      
	  }

Output:

Your output looks like this:

Now I want my overlay text is invisible at first and visible only on mouse hover. So, one way you can do it by applying opacity. Put opacity 0 at the beginning and change the opacity to 1 upon mouse hover. Add the below line to your above code.

opacity:0;

Now, your code looks like this

.overlay-box {
        position: absolute;     
        opacity:0;
        top: 50%;
  	left: 50%;
  	transform: translate(-50%, -50%);
  	-ms-transform: translate(-50%, -50%)      
	  }

Here is an output after putting opacity 0:

Now, it’s time to change the image and text opacity. Initially, we defined image opacity as 1. Now change to 0 upon the mouse hovering over an image. And, text opacity was defined as 0, now changed to 1 upon mouse hover.

Add the below code to your CSS style sheets.

.container:hover .image {
 		 opacity: 0.5;
	   }
      
      .container:hover .overlay-box
      {
        opacity: 1;
 	  }

Output:

Now, see the output after adding the above code.

Fade In A Box

CSS Image Hover Fade In A Box
Fade In A Box


Now, it’s time to design your text and give more professional look. Add the below code for your text design:

.text{       
        background-color: #008000;
        color: white;
        font-size: 14px;
        padding: 10px 15px;  
      }

See the output now:

Fade In A Box

CSS Image Hover Fade In A Box
Fade In A Box


Donate to support writers.


You may be interested in the following topics:

CSS Image Hover Overlay Fade In Text

Please Share On:

Definition:

To display the overlay text on mouse hover, let’s start to design your code from the beginning.

First of all, create a container and put an image inside that container, create an overlay and put text inside it like the below example.

CSS Image Hover Fade In The Text
Fade In Text

Now, let’s start designing.

<!DOCTYPE html>
<html>
  <head>
 
  </head>
  
  <body> 
      <h3 class="title">Fade In Overlay</h3> 
      <div class = "container">
          <img src="https://www.elsebazaar.com/blog/wp-content/uploads/2019/03/About-Us-image.jpg" alt="Fade In Overlay">
        
        <div class="overlay">
    		<div class="text">Fade In Overlay</div>
  		</div>
      </div>   
   
  </body>
</html>															
					

Output:

Fade in overlay text



Now, style your container and image. Make sure you keep your container position relative and container width will be your design requirement. Here, I have given 50%. You can give 10%, 20%, 100%, or your chosen position.

.container {
         position: relative;
         width: 50%;
      }

Now, we need to design images. Add the below code to your style sheet.

img {
        display:block;
        width: 100%;
        height: auto;
      }

Output:

Your output looks like this.

Fade in overlay position


Now, it’s time to design your overlay. The overlay must be the same size as your image and in an absolute position. Here, I have added an overlay background color in light blue. Now, add the below code to your style sheet.

.overlay {
        position: absolute;
        height:100%;
        width:100%;
        background-color: lightblue;
	  }

Output:

Your output looks like this:

overlay background-color

Now, I want my overlay text to stay absolute behind my image. To do this, add the below code in your above .overlay style sheet.

top: 0;
bottom: 0;
left: 0;
right: 0;

The code looks like this

.overlay {
        position: absolute;
        height:100%;
        width:100%;
        background-color: lightblue;
        top: 0;
	bottom: 0;
	left: 0;
	right: 0;
	  }

Output:

Now, see the output after adding the above code.

output after overlay


Here, you can clearly see that the overlay text has covered your image which is supposed to stay in the background and the image should be seen in the front. To display your image, keep the overlay opacity to 0 before the mouse hover.

opacity: 0;

Add the opacity in your .overlay and also add a transition for overlay

transition: .5s ease;

Output:

Here is an output after you add opacity zero in your overlay text.

fade in overlay opacity

Now, it is time to style the mouse hover effect and display overlay text. When we hover a mouse on the image, the image must disappear, and overlay text should display. To do this, apply overlay opacity to 1.

.container:hover .overlay {
        opacity: 1;
}

Output:


Before Mouse Hover

After Mouse Hover


Now, let’s design the text and keep it in the center. Add the below code to keep your text in the center

.text{
        position:absolute;
        top:50%;
        left:50%;
        transform: translate(-50%, -50%);
       -ms-transform: translate(-50%, -50%);
      }

Output:

See an overlay text at the center:

overlay text at the cneter

Output:


Donate to support writers.


You may be interested in the following topics:

CSS Image Hover Overlay

Please Share On:

Definition:

The image hover overlay effect is used for different image effects. Click on each link to learn more in detail.

  1. Fade in a text
CSS Image Hover Fade In The Text
Fade In Text

2. Fade in a box

CSS Image Hover Fade In A Box
Fade In A Box

3. Slide from the top

CSS Image Hover Fade In A Box
Slide from the top

4. Slide from the bottom

CSS Image Hover Fade In A Box
Slide from the bottom

5. Slide from the left and

Image Hover Overlay Slide From The Left
Slide from the left

6. Slide from the right

CSS Image Hover Overlay Slide from the right
Slide from the right

7. Image Overlay Zoom

CSS Image Overlay Zoom
This is a Opera House.

8. Image Overlay Title

Image Overlay Text
This is Opera House

9. Image Overlay Icon


Donate to support writers.


You may be interested in the following topics:

Copyright @2023. All Right Reserved.


Social media & sharing icons powered by UltimatelySocial