Having difficulty incorporating a video into the background

After searching online and attempting two different methods, I am still unable to achieve the desired result.

I want a video to cover the entire background of my webpage. Here is what I have tried:

CSS -

video#bgvid {
    position: fixed;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    -ms-transform: translateX(-50%) translateY(-50%);
    -moz-transform: translateX(-50%) translateY(-50%);
    -webkit-transform: translateX(-50%) translateY(-50%);
    transform: translateX(-50%) translateY(-50%);
    background: url(polina.jpg) no-repeat;
    background-size: cover;
}

HTML -

  <video playsinline autoplay muted loop poster="img/videoframe.jpg" id="bgvid">
        <source src="https://streamable.com/kuuap9" type="video/mp4">
    </video>

Unfortunately, this does not display anything as the website background. Am I overlooking something or is there a simpler solution?

Another method I attempted without success is as follows:

CSS-

.fullscreen-bg {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
    z-index: -100;
}

.fullscreen-bg__video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

HTML-

<div class="fullscreen-bg">
    <video playsinline autoplay muted loop poster="img/videoframe.jpg" id="bgvid">
        <source src="https://streamable.com/kuuap9" type="video/mp4">
    </video>
</div>

Any assistance or guidance would be greatly appreciated. Thank you!

Answer №1

To access the video, simply download the file or use a URL ending in .mp4

Then, add the following code snippet to your HTML:

#bgvid {
         width:100%;
         height:100vh;
         position: absolute;
         z-index:-1;
}

Answer №2

Don't forget to update your HTML with this Code

<video controls playsinline autoplay muted loop poster="img/videoframe.jpg" id="bgvid">
    <source src="https://streamable.com/kuuap9" type="video/mp4">
    Unfortunately, your browser doesn't support the video tag.
</video>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Android webview fails to load the page, but the app successfully loads it when accessed through the

I'm experiencing an issue with my HTML5 mobile web app loading fine in a browser but getting stuck on an Android webview. We have implemented a splash screen before loading the web app, but the webview seems to be stuck on the splash screen and does n ...

Ways to obtain the chosen option from a drop-down menu using jQuery

I'm currently experiencing an issue where the selected value of a drop down is not being displayed correctly. Instead of selecting the dropdown value, it's adding another value to the list. Below is the code snippet I'm using: JQuery var ...

The image does not automatically adjust size when the window is resized

I'm having an issue with my HTML and CSS code that is supposed to display two images side by side and resize when the browser window shrinks, but it's not working as expected. Even after removing all classes on the parent divs, the images still ...

Tips for handling null input values when saving to a database

<!DOCTYPE html> <html> <head> <title>Data</title> </head> <body> /* Enter your data here */ <form action="this.php" method="post"> <input type='text&a ...

Tips for utilizing identical properties across numerous styled elements:

Utilizing the styled-components library, I have enhanced the header components from the Blueprintjs library. The current template for the H6 component appears as follows: export const DH6 = styled(H6)` color: ${(props) => (props.white ? "white&qu ...

Is the issue of Padding Overlap with Sidebar Item List getting in the way?

I am currently new to coding in HTML and CSS, so please bear with me if my code seems outdated or unconventional. I am working on creating a basic test website with a sidebar, but I'm encountering an issue where the items in my list are overlapping du ...

Issue arises when attempting to compile .less file with variables sourced from a separate file

I encountered an issue with my .less file where it contains definitions that rely on variables from another file. For example: body { font-family: @baseFontFamily; font-size: @baseFontSize; color: @textColor; } At first, IntelliJ displayed t ...

What is preventing me from creating accurate drawings on canvas?

I'm currently working on a paint application and facing an issue. When I place the painting board on the left side of the screen, everything works fine and I can draw without any problems. However, when I move it to the right side of the screen, the m ...

Using functions like nl2br() for new line breaks, preg_replace for replacing patterns, htmlspecialchars() for encoding special

I've reviewed all the answers on this topic, but I'm still struggling to find the correct method for sanitizing data. My task is to enter: <?php echo 'yes'; ?> <?php echo 'yes' ?> into a text area, submit it in ...

Using CSS to position elements absolutely while also adjusting the width of the div

In one section of my website, I have a specific div structure. This structure consists of two divs stacked on top of each other. The first div is divided into two parts: one part with a width of 63% and another part with a button. Beneath the first div, t ...

Using Handlebars, you can easily interpolate variables within an "each" loop

I have integrated this code into an express app that utilizes handlebars as its template engine: res.render("movies", { data: pages, arraypages:arrayPages, movie:movie}) The "arrayPages" variable is represented by an array: [ 1, 2, 3, ...

How can I resize an element using jQuery resizable and then revert it back to its original size with a button click?

I need help figuring out how to revert an element back to its original size after it has been modified with .resizable. I attempted the following: <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="//code. ...

The Selenium driver's execute_script() function is not functioning as expected

When I attempt to execute a JavaScript using driver.execute_script, nothing happens and the system just moves on to the next line of Python code. Any ideas? I've been web scraping on a webpage, using JavaScript in the Console to extract data. The Jav ...

How can SQL data be loaded following the selection from a dropdown menu?

I have a pressing query that I need assistance with. I am aiming to achieve a certain task, but due to lack of prior experience in this area, I am unsure about how to proceed. My current situation involves populating a dropdown menu with names retrieved f ...

How can I include line breaks using HTML `<br>` tags in a textarea field that is filled with data from a MySQL

Within a modal, I am showcasing a log inside a read-only <textarea> field that contains data fetched from my MySQL database. Below this, there is a writable <textarea> field where users can input updates to the log, which are then added to the ...

Guide on exporting Excel data using Angular and TypeScript

My project involves managing a table of information that includes fields for FirstName, LastName, PhoneNumber, Age, and Date. I've created a function that allows me to export the data to an Excel file, but I only want to export specific fields like Fi ...

Proper Alignment of Multiple Elements Floating to the Right in a Menu

Although this question has been asked previously, I am facing challenges in getting it to work for my specific scenario. My objective is to showcase a menu bar with a search option and inline text to its left. However, when I attempt to float both elements ...

Is it possible to align a CSS table row with its corresponding table header even when the table row is deeply nested within the table structure?

I am looking to keep the structure of my HTML code consistent and unaltered. However, this has resulted in a form tag being nested inside a table row before the table cells can begin. The information I need to display is tabulated data, which makes CSS t ...

Rearrange the order of items in the fancybox gallery

Typically, fancybox displays items in the gallery based on the order they are added in the HTML code. Is there a way to customize the order of items when they are opened in the popup, while keeping the original order when displayed on the page? The solut ...

How feasible is it to customize the "ionic-img-viewer" npm package or replicate its image styling in Ionic 2?

I am wondering if it is possible to edit or add additional styles when my image is viewed using the "ionic-img-viewer" npm package. Alternatively, how can I apply the same styles as those on my original image tag? For example, here is my img tag with some ...