Add a video background to your landing page to make it more gorgeous

In this blog, you will learn how to add a video background to your landing page to make it more gorgeous.Preview:https://medium.com/media/8ee8368f80deb52a2d9345b6d811f367/hrefRequirements:Basic HTML & CSS knowledgeBasic Javascript(Optional. only re…


This content originally appeared on Level Up Coding - Medium and was authored by Anjan Shomodder

In this blog, you will learn how to add a video background to your landing page to make it more gorgeous.

Preview:

Requirements:

  • Basic HTML & CSS knowledge
  • Basic Javascript(Optional. only required for the navigation toggle effect)

I have already created a video about it on my youtube channel. Check that out for more details.

If you like this video, please like share, and Subscribe to my channel.

source code: https://github.com/thatanjan/video-background-landing-page-yt

Starter code

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Taylor Swift</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="nav.css" />
<link rel="stylesheet" href="content.css" />
<link rel="stylesheet" href="responsive.css" />
</head>
<body>
This is body

<script src="index.js"></script>
</body>
</html>

Let’s add the video and overlay to html.

<section class="video_container">
<video src="./media/background.mp4" autoplay loop muted></video>
<div class="overlay"></div>
</section>

Result:

Explanation:

A video container to contain the video and overlay.
Video will be started automatically with a loop. It will also be muted.
Css reset

* {
padding: 0;
margin: 0;
box-sizing: border-box;
}

body {
max-width: 100vw;
overflow-x: hidden;
}

Explanation:

The entire webpage should not be bigger than the screen width.
The webpage will not have any horizontal scrolling.
Let’s style the video:

.video_container {
min-height: 100vh;
max-height: 100vh;
overflow: hidden;
position: relative;
}

.video_container video {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
object-fit: cover;
object-position: center;
}

Result:

Explanation:

The video container is taking the full width of the screen without any overflow. It is also positioned as relative.
The actual video is positioned absolute and aligned with the container. It is also taking the full height and width.
If you have confusion with CSS position then you can watch this video.

  • To make the video fit, we need to use object-fit to cover.
  • If the user adjusts screen width, the user will always see the center of the video because of object-position: center;.

By the way, this blog is originally published on the Cules Coding website. I would be glad if you give it a visit.

Let’s style the overlay.

:root {
--primary-red: #70000e;
}

.overlay {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: var(--primary-red);
mix-blend-mode: soft-light;
}

Result:

Explanation:

  • The overlay element is aligned with the container using the position absolute.
  • The background color is stored inside a variable. If you don’t know about CSS variables, then you can check out this blog
  • Overlay has been blended with the background using a blend mode. We need to use mix-blend-mode property to do so. I will use soft-light it as value. You can learn about mix-blend-mode from here

And that’s how you add a video background to a landing page to make it more gorgeous. If you want to learn how the rest of the project was made please watch the video.

source code: https://github.com/thatanjan/video-background-landing-page-yt

Shameless Plug

I have made a few project-based videos with vanilla HTML, CSS, and JavaScript.

You will learn about:

  • Javascript intersection observer to add cool effects
  • DOM manipulation
  • Aligning elements with CSS positions.
  • How to make responsive websites.

These will be great projects to brush up on your front end skills.

If you are interested you can check the videos.

Please like and subscribe to Cules Coding. It motivates me to create more content like this.

That’s it for this blog. I have tried to explain things simply. If you get stuck, you can ask me questions.

By the way, I am looking for a new opportunity in a company where I can provide great value with my skills. If you are a recruiter, looking for someone skilled in full stack web development and passionate about revolutionizing the world, feel free to contact me. Also, I am open to talking about any freelance project.

See my work from here

Contacts


Add a video background to your landing page to make it more gorgeous was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Anjan Shomodder


Print Share Comment Cite Upload Translate Updates
APA

Anjan Shomodder | Sciencx (2022-04-03T22:59:03+00:00) Add a video background to your landing page to make it more gorgeous. Retrieved from https://www.scien.cx/2022/04/03/add-a-video-background-to-your-landing-page-to-make-it-more-gorgeous-2/

MLA
" » Add a video background to your landing page to make it more gorgeous." Anjan Shomodder | Sciencx - Sunday April 3, 2022, https://www.scien.cx/2022/04/03/add-a-video-background-to-your-landing-page-to-make-it-more-gorgeous-2/
HARVARD
Anjan Shomodder | Sciencx Sunday April 3, 2022 » Add a video background to your landing page to make it more gorgeous., viewed ,<https://www.scien.cx/2022/04/03/add-a-video-background-to-your-landing-page-to-make-it-more-gorgeous-2/>
VANCOUVER
Anjan Shomodder | Sciencx - » Add a video background to your landing page to make it more gorgeous. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/03/add-a-video-background-to-your-landing-page-to-make-it-more-gorgeous-2/
CHICAGO
" » Add a video background to your landing page to make it more gorgeous." Anjan Shomodder | Sciencx - Accessed . https://www.scien.cx/2022/04/03/add-a-video-background-to-your-landing-page-to-make-it-more-gorgeous-2/
IEEE
" » Add a video background to your landing page to make it more gorgeous." Anjan Shomodder | Sciencx [Online]. Available: https://www.scien.cx/2022/04/03/add-a-video-background-to-your-landing-page-to-make-it-more-gorgeous-2/. [Accessed: ]
rf:citation
» Add a video background to your landing page to make it more gorgeous | Anjan Shomodder | Sciencx | https://www.scien.cx/2022/04/03/add-a-video-background-to-your-landing-page-to-make-it-more-gorgeous-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.