Believemy logo purple

Creating a hovered with CSS

In this tutorial we'll look at how to create an overlay easily using CSS!
Updated on December 9, 2024
Believemy logo

In this first article in the history of BELIEVEMY, let's see together how to create a hovered effect: text that appears when you hover your mouse over an image!

You can find the entire tutorial on our Instagram account

 

Step 1

In this first step, we will start by displaying an image:

HTML
<img src="logo-believemy.png" alt="Logo" />

 

Step 2

Crop and wrap the image in a div:

HTML
<div class="container">
    <!-- Image -->
    <img src="logo-believemy.png" alt="Logo" />
</div>

And on the CSS side:

CSS
.container {
    position: relative;
    width: 500px;
}
.container img {
    width: 100%;
}

 

Step 3

Add the text to display:

HTML
<div class="container">
    <!-- Image -->
    <img src="logo-believemy.png" alt="Logo" />
    
    <!-- Text to display -->
    <div class="hovered">Hello World!</div>
</div>

And on the CSS side:

CSS
.hovered {
    position: absolute;
    top: 0; bottom: 0; left: 0; right: 0;
    height: 100%; width: 100%;
    opacity: 0; transition: all .3s;
    background-color: #3f3f44;   
}

Here, we set the overlay to absolute position to place it correctly and initially hide it by setting its opacity to 0.

The top, bottom, left, and right properties make it take up the entire space.

 

Step 4

Make the overlay appear when the mouse hovers over the image, and do all this using only CSS.

CSS
.container:hover .hovered {
    opacity: 1;
}

When the mouse hovers over the container class (thus over the image), we set the opacity of our overlay class to 1 to display its content.

 

Step 5

Center the text of the overlay by wrapping the text in a span tag to better select it with CSS.

HTML
<div class="container">
    <!-- Image -->
    <img src="logo-believemy.png" alt="Logo" />
    
    <!-- Text to display -->
    <div class="hovered">
        <span>Hello World!</span>
    </div>
</div>

Finally, we select the span tag within the overlay class and center everything!

CSS
.hovered span {
    color: white;
    font-size: 5rem;
    position: absolute;
    top: 50%;
    left: 50%;
    font-family: arial;
    -webkit-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}

And here we are with a superb hovered effect!

Category: Development
Believemy logo
Comments (0)

You need to be logged in to comment on this article: log in or sign up.

Try for Free

Whether you're scaling your startup, building your first website, or transitioning to a developer role, Believemy is your new home. Join us, grow, and let’s build your project together.

Believemy is with anyone