How To Show a Background Overlay and The Content of a Column on Hover in Elementor
Tags: wordpress, webdev, css
Published: 2020-08-21 22:48:53

In this post, I am going to show you how to display a background overlay of a column and the headline widget on top of it when the user hovers over the image. The final product would be like this:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/57z2dqo6ww9qgb2y7c5e.gif)

Cool, isn’t it? So let's get started!

## Set Up The Image and The Content

Add a new section and choose the two-column structure. Then click Edit Column. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/diduf3rfzhkqpiuvn350.gif)

In _Style > Background > Background Type_ choose **Classic**. Then under _Image_ click the **+** sign to add the Image you want to display.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/mirradgsfef4pqk26dzs.gif)

For now, you'll only see a very small portion of the image. No worries, it happens because our column doesn’t have any content yet. So let's add a Headline Widget on it.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/gbkqcs2ddorh35jmmh93.gif)

Why is it still the same? Since our Headline widget is only a one-line content, then the column doesn't get much additional height. 

However, by adding this content now we can adjust the column padding and see the change. If you do it before adding the content, you won't see the result until you place the content. Do you get it?

Now let's adjust the padding. 

Click Edit Column and go to Advanced tab. Before we add the padding, let's turn off the Link Values Together button so we can set each padding value individually. 

Now set the padding for the top and bottom value to make the column stretched vertically. You can play around with the number, but for the purpose of this tutorial let's set it to 300 hundred since I know it'll look good. 

Please note that we make the top and bottom padding identical because we want the content to be vertically centered. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/6rb5cxgdc3p8qmj25cdm.gif) 

Alright, now we've successfully made our image visible, but it only shows us a small part of it. We don't want that right? Let me show you how to fix it.

Go to _Style > Background_ and set the **Position** to Center Center. Next, change the **Repeat** to No Repeat. Lastly, set **Size** to Cover. 

Voila, now we have a beautiful image that takes half of our screen. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n3qn1euxrf53b5wk08a7.gif)

## Set The Overlay

Now we've our image set up, then our next step would be setting up the background overlay. Let's proceed.

Go to _Style > Background > Hover. Next, choose Classic for the Background Type and set the color. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hvwq2m7fnu4b8ly3igps.gif)

If you do it right, now you should have a column filled with an image that shows a background overlay on hover. And that's it for the image. 
 
## Adjusting the Text

Before we move on, let's change the content of our Headline widget into something more meaningful. I'll change it to "A Cozy House with Sea View". 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dqdgwm1kuiqu3b1xi6ms.gif)

Now let's edit the color so it goes well with our background overlay. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/rjg6n1vwgbsmjpehsq1w.gif)

Look good? 

I think yes, except for one thing: the text is too close to the edge of the image. Let's add some padding to it so it has more room to breathe. 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pmb8pzbxiulrjstmo4rj.gif)

And that's it. Now we have text on top of an image with an overlay on hover. 

Our next step would be to hide the text on the normal view before we can reveal it on hover.  

## The CSS Code

To hide our text, we need to set the opacity to 0. For this task, we need to set it manually using CSS since there is no such an option in the Elementor editor.

There are two steps in using CSS to customize the Elementor widget. First, we need to give the widget a CSS Class or ID name. Second, we need to write the CSS code itself. 

Let's do it.

Go to Advanced tab and give the CSS Classes a name. I'll name it 'my-hidden-headline'.  

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/yhb4lolvv1xtbiys1lx2.gif)

Then, we need to give our column a CSS Class name too so we can target it when the user hovers on it. 

Go to Advanced tab and fill the CSS Class with a name, let's name it 'my-bg-overlay'.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9xynxsyl84ywpi77oess.gif)

Why we use CSS Class instead of ID? I prefer to use class than id because it opens up the possibility to use it more than once on the same page. In our case, it means that we can use the 'my-hidden-headline' again for other Headline widgets somewhere on this page. If we use ID, that will be only for that specific widget.

Now, before we add our CSS code in the theme customizer, let’s save our changes first. So, click UPDATE and view your page.

Then click Customize and copy the following code:
{% gist https://gist.github.com/jprumekso/facf2c306a4fef7d94486515c4f03722 file=hide-headline-widget.css %}

After that, paste that code into Additional CSS setting panel and click Publish.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1l992pt03qmf7r0xkqik.gif)

What we are doing here is targeting the my-hidden-headline class and set its opacity to 0 so it becomes hidden on the normal view. 

Finally, copy this code:
{% gist https://gist.github.com/jprumekso/facf2c306a4fef7d94486515c4f03722 file=show-headline-on-hover.css %}

and paste it below the previous code. This final code set the headline widget opacity back to 1 when the my-background has hovered.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wizvjf854lpmc60lgcf1.gif)

Please note that we use the transition property so the Headline reveals smoothly.

## Conclusion

That's it, now when your user hovers over the image, it will display the background overlay and the text. 

To sum up, here's what we've learned in this tutorial:
* Adding image to a page via column background image setting
* Adjusting the padding to control the size of a column
* Adding background overlay on hover
* Giving an element a unique CSS class name.
* Hiding text via CSS
* Finally, showing text on hover.        

If you found this tutorial helpful please leave a comment and feel free to request another Elementor or WordPress customization tutorial as well.