Like our free content? Then you'll love our exclusive Club!
Divi Academy Membership gives you exclusive access to over 110 resources, including child themes, layouts, cheatsheets, tutorials, live training and member perks. And new content is added EVERY Monday!
Recipe #24 is something I have seen asked in the Facebook groups several times lately, how to add a transparent image overlay to a background video. There are a few ways to do this and in this recipe I am going to show you two.
We are going to use the fullwidth header module as this is most commonly where a background video is used, and this module also gives us the option to easily add a heading, subheading and buttons.
This is actually a lot simpler to do that it looks and uses very minimal CSS but the main difficulty is, as I explain in this post, the background image element doesn’t have its own class so we can’t target it. But there are ways around that
Watch the video, get the code you need in the accompanying blog post, be sure to scroll to the bottom for your fabulous freebie, and let me know what you think in the comments!
So let’s get cooking!
Ingredients
The Divi Theme from Elegant Themes.
A video to use for your background. You can get some great free ones at coverr.co and that is where I got the one used in the demo.
An image to use as your overlay. Dimensions of 1920 x 1080px are perfect for a fullscreen video, and a jpg is fine, you don’t need to create a transparent png with this method and a jpg is actually better as generally the file size will be smaller.
Cooking time
This should take you around 5 minutes max.
Preparation
The first thing we need to do it set up our fullwidth header with a video background, so add a fullwidth section and a fullwidth header module to your page.
Next, open up the section settings and click on the Upload a Video button next to the Background Video MP4 field, add your video to the media library and select it to add it to the section. Whilst you are in your media library, also upload the image you are going to use for your overlay and make a note of the URL. Then Save & Exit.
That’s our prep done.
Method
The first method I am going to show you is the overlay with solid text and buttons, this is the first example in the demo.
Open up the module settings and add your title and subheading, set your text colour and orientation and set make fullscreen to yes. You don’t have to use fullscreen, this will work without that option too but it’s a nice effect.
If you want buttons on your header then scroll down a bit further and add in your button text and urls and make any adjustments you want to the text and buttons in the Advanced Settings Tab. Then click on the Custom CSS tab and give your module a CSS class of ds-video-image-overlay1
Now for the CSS.
Copy and paste the CSS below into your child theme stylesheet, Divi options custom CSS box or the page specific CSS box and change the URL to the URL of your overlay image that you added to the media library earlier.
What we are doing here is using the :before Pseudo Element to add our overlay image to the module, we are positioning it absolutely with a top and left position of 0 so it sits over the top of our video, making it 100% of the width and height of our module and setting the opacity to 0.5 to give it transparency.
.ds-video-image-overlay1.et_pb_fullwidth_header:before { content: url(https://divisoup.com/wp-content/uploads/2016/09/building-2.jpg); position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: .5; }
And that’s it. Now preview your header and you should have a video background with your transparent image on top. You can increase or decrease the opacity property in the CSS to have the image more or less transparent.
Now for the second method. This option requires even less CSS and it also makes the text and buttons in the header transparent too. This means the video slightly shows through the header content giving a nice animated effect. You can see on my demo how the text gets brighter when the people walk past behind it.
You need to follow all the same steps as in the previous method but with two slight changes:
In the Module Settings, scroll down and add your overlay image directly to the Background Image URL field.
Then click on the Custom CSS tab and give the module a CSS Class of ds-video-image-overlay2 and then Save & Exit
Now instead of the previous CSS, add the following:
.ds-video-image-overlay2.et_pb_fullwidth_header { opacity: .5; }
All we are doing here is setting the entire fullwidth header module to have an opacity of 0.5, which is what creates the effect where the video slightly shows through the header content.
Now preview your header and you should have something similar to the second example in my demo.
You will probably want to create a different header to show on tablet and mobile as videos use a lot of data
And that’s it.
If you found this helpful please leave a comment and subscribe to my newsletter for all my latest Divi related content.
Michelle X
Not working for me. I added your code and see your image flash but then the video goes on top of it. Candidww.website
Demo at https://divisoup.com/background-video-image-overlay/ is working OK for me. I don’t see an overlay on your site.
Thanks for this! Worked marvelous for me.
Thanks for your reply Michelle..
I don’t think there is 2 overlay there.. I believe I followed the steps exactly..
I just tried in the demo page for this tutorial.. it is the same.. Try go to the browser and resize the screen.. for example, at default of 100%, lower it to 80% or 67% or lower.. you will see this.. : http://prntscr.com/ea299b
Is there a way we can permanently stretch the image so this does not happen on users who have adjusted these browser screen size settings..
Thanks and much appreciated..
Hi Andrew, sorry I see what you mean now. Yes that is just zooming in and out of the browser, which the average user would not do. Not much I am aware of you can do to control how things display in that scenario I am afraid
Hi Michelle! Thank you for this great tutorial..
If you have the time, I just have a question.. if I re-size the screen on the browser, the overlay picture does not cover the whole screen.. I’m using a picture that has a width of 1920
It will become like this: http://prntscr.com/e8lzwl
Is this normal? Thanks and thank you very much..
This is the link… http://vekrotecsea.com/
Andrew the overlay is going the full height but you seem to have 2 overlays, one on the video and one on the image, is that correct?
Hello Michelle!
Same problem.
“Zak Katz on October 27, 2016 at 9:08 pm
Hey Michelle – this is a great tutorial. I tried adapted your recipe for just a regular section, and used the following CSS and just can’t seem to get it working:
.ds-video-image-overlay1.et_pb_section_0:before {
content: url);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: .5;
}
”
Maybe “et_pb_section_0” isn’t correct for my page? Can you help me? I use regular section with video background. Also my section is the first section on the page.
Yes you could be targetting the wrong section. Did you give the section a custom class of ds-video-image-overlay1 ?
Try this
.ds-video-image-overlay1 .et_pb_section:before {
content: url);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: .5;
}
Hello Michelle, I have 3 questions about this blog post: 1) Sometime it load super slow in safari and this stops all image animation underneath the fullwidth header. Is this a problem with Divi? Do you know of any way I can fix this? The video I am using is 49MB. Here the link to my test: http://besocialsolutions.com/byfar/avantages/ 2) Is it possible to turn this into a Divi Plugin? If so, can you point me to blog post on the subject? 3) If I want to implement this on all my live project should I just upload my new child… Read more »
Hey Gabriel, I replied to your earlier comment about the video. As for a plugin, yes its possible but I haven’t tried it yet, you could try making it into a module, there are instructions here https://jonathanbossenger.com/building-your-own-divi-builder-modules/#comment-2842.
Course should be live early March
Hi, 1st let me tell you your blog is amazing and I will definitely buy a subscription to your course you should be live any time now I guess. The video effect is amazing and I have 5 ongoing project at the moment that would like to implement it. Unfortunately, I noticed that the code is not working very well for me on Safari, the video does for ever to load and my images underneath the fullwidth header to not appear (when I scroll down) until the video is fully loaded (i guess the animation is being stopped). I did… Read more »
Hey Gabriel, you really can’t use a 49mb video I’m afraid you will need to find a way of compressing that or shortening the video
Hey Michelle,
Great article.
I wonder if you could tell me how to add a white overlay (with opacity) over the video on http://www.mostachomarketing.com/
Thanks
Thais should do it:
.et_pb_section_video_bg video:before {
content: ”;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgbs(255,255,255,.5);
}
This tutorial rocks (as usual) :). I have a question though: I am using this for a website, where I added a video in mp4 format, which we made ourselves (because this guy is in a specific area where it is not easy to find an out of the box video). But.. my video has sound, and I want to mute that. Is there a simple code to achieve this?
Thanks,
Helen
Thanks Helen, I haven’t used it but try this https://gist.github.com/lots0logs/66426a98f156484b2bbc
I tried a few things, and the funny part: the simplest solution is usually the best: Windows Movie Maker
Great tutorial! I do have two follow-up questions.
1. In my effort on this, the .mp4 does not appear on mobile. It’s just a white background.
2. When viewing in mobile, the two buttons don’t quite align centered, they’re skewed, probably because we didn’t set that parameter up. How would I add that piece just for mobile?
Thanks again. Really appreciate the teaching!
Brandon, Divi removes videos on mobile automatically. You can try using a standard section and making it fullwidth, not sure off the top of my head whether the video will be removed there also.
The buttons issue is something that bugs me with Divi, the first button has right margin for spacing but this isn’t removed for mobile so when they stack they are off. You will need to do this manually. I usually just overide it but adding a little margin all the way round to both buttons so they stack properly.
Hey Michelle – this is a great tutorial. I tried adapted your recipe for just a regular section, and used the following CSS and just can’t seem to get it working:
.ds-video-image-overlay1.et_pb_section_0:before {
content: url);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: .5;
Any ideas?
I am not sure what you are trying to achieve, there is nothing underneath the image so the opacity won’t work. Also the code you posted doesn’t have a closing racket so not sure if that is present in your actual code. If you can provide a little more detail?
Hi, trying to achieve the same.. I would like to use this on a regular section (not full width), because I want to be able to add blurbs over the background. Any pointers on that?
Should work fine on a regular section Helen but tbh I havent tried yet
Great tutorial, I will certainly use it on one of my next project.
If someone is looking for videos, there is this website : http://www.coverr.co/
Best,
Bastien
Hi Michelle! I implemented today on my site http://achieveit360.com/ and am thrilled with the results! Thank you!!! Going to work on more pages tomorrow. So grateful for your recipes! I almost fell off my chair when I saw a new one come in!
PS- mine doesn’t work on a mobile…should it?
No from memory Divi switches it off on mobile which is a good thing as video use so much data. I would suggest creating a separate module for mobile
Welcome Andrea
Merci , beaucoup , pour votre travail partagé.
Thank’s a lot!
Gérard
Je vous en prie
Beautiful effect Michelle. Thanks for all you do in the Divi community.
My pleasure Simon
Beautiful work again Michelle as always! Many thanks for sharing.
Thank you Carl
Do I add the CSS inside the divi theme options or inside the module itself? My apologies, I’m not a coder but I really like this technique!
John you can add to Divi theme options or your child theme stylesheet, not the module though.
Okay thanks.
Another great recipe! Thanks for making it so easy to make my sites look so much nicer. I love having the two options of solid and transparent text. One question – do you have a max file size for your video? Thanks!
Thanks Maureen I don’t actually use video in my sites this way very much at all so couldn’t advise on an ideal file size. I was able to get that video to around 1.3mb which I think is quite acceptable, I guess I would aim for 1mb or below ideally but that can be difficult. I found a nice particle effect video I wanted to use but I just couldn’t get it below 5mb.