The background video on the website is having trouble resizing properly to fit the screen dimensions

I'm new to coding and I'm attempting to incorporate a background video on the homepage. The issue arises when I resize my window or view it on a mobile device, as the video fails to adjust to the window size, causing side scrolling that reveals the hidden menu for mobile view.

Here is the current code for the background video and entire page:

HTML and CSS:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page Title</title>
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="style.css">
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<section class="header">        
    <nav>
        <a href="index.html"><img src="images/logo.png"></a>
        <div class="nav-links" id="navLinks">
            <i class="fa fa-times" onclick="hideMenu()"></i>  
            <ul>
                <li><a href="">HOME</a></li>
                <li><a href="">STUDY</a></li>
                <li><a href="">PROPERTIES</a></li>
                <li><a href="">LOGIN</a></li>
                <li><a href="">CONTACT</a></li>
            </ul>
        </div>
        <i class="fa fa-bars" onclick="showMenu()"></i>
    </nav>
    <video autoplay muted loop id="myVideo">
        <source src="images/video-test.mp4" type="video/mp4">
    </video>  
    <div class="text-box"> 
        <h1>TITLE</h1>
        <p>subtitle</p>
    </div>
</section> 


<!-------- JavaScript for toggle Menu -------->
<script>

    var navLinks = document.getElementById("navLinks");

    function showMenu(){
        navLinks.style.right = "0";
    }
    function hideMenu(){
        navLinks.style.right = "-200px";
    }

</script>

</body>

</html>

*{
    margin: 0;
    padding: 0;
    font-family: 'Open Sans', sans-serif;
    }
    
    /* old background image, there is none */
    .header{
    min-height: 100vh;
    width: 100%;
    background-color:white;
    background-position: center;
    background-size: cover;
    position: relative;
    }

    /* background video */
    #myVideo {
        position: static;
        right: 0;
        bottom: 0;
        min-width: 100%;
        min-height: 100%;
        object-fit: cover;
        overflow: hidden;
    }


    /* logo, navigation (about etc) + animation quand on va sur le txt */
    nav{
    display: flex;
    padding: 2% 6%;
    justify-content: space-between;
    align-items: center;
    }
    nav img{
    width: 90px;
    }
    .nav-links{
    flex: 1;
    text-align: right;
    }
    .nav-links ul li{
    list-style: none;
    display: inline-block;
    padding: 8px 12px;
    position: relative;
    }
    .nav-links ul li a{
    color: black;
    text-decoration: none;
    font-size: 13px;
    }
    .nav-links ul li::after{
    content:'';
    width: 0%;
    height: 2px;
    background: black;
    display: block;
    margin: auto;
    transition: 0.2s;
    }
    .nav-links ul li:hover::after{
    width: 100%;
    }
    
     /* title and subtitle */
    .text-box{
    width: 90%;
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: left;
    }
    .text-box h1{
    font-size: 62px;
    }
    .text-box p{
    margin: 10px 0 40px;
    font-size: 16px;
    color: white;
    }

    /* mobile view*/

    nav .fa{
        display: none;
    }
    
    @media(max-width: 700px) {
        .text-box h1{
            font-size: 62px;
        }
        .nav-links ul li{
            display: block;
        }
        .nav-links{
            position: absolute;
            background: rgb(255, 255, 255);
            height: 100vh;
            width: 200px;
            top: 0;
            right: -200px;
            text-align: left;
            z-index: 2;
            transition: 0.6s;

        } /* problème d'affichage du menu sur tel */
        nav .fa{
            display: block;
            color: black;
            margin: 10px;
            font-size: 22px;
            cursor: pointer;
        }
        .nav-links ul{
            padding: 30px;
        }
    } 

Answer №1

Ensure your video fills the whole container by including width: 100%;

    #myVideo {
        position: relative;
        left: 0;
        top: 0;
        width: 100%;
        min-width: 100%;
        min-height: 100%;
        object-fit: cover;
        overflow: hidden;
    }

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

How can I upload a file using the following HTML script with Selenium in Python?

I attempted to utilize the send_keys() method directly on an attached path file, but encountered an error. Can anyone provide guidance on how to properly upload a file? Here is my Selenium Python script: from selenium import webdriver from selenium.webdri ...

The HTML grid is causing an irritating excess space on the right side of my website

After brainstorming an idea, I decided to create this website for testing purposes. However, the grid layout seems to be causing an unwanted margin on the right side of the page that is not associated with any HTML tag, disrupting the zoom functionality. ...

What is the best way to refresh information following its removal?

In my app, I have implemented a feature where posts are displayed as HTML cards using a component called PostList. Each card has a delete button to remove it from the list. The issue I am facing is that when I delete a card, it remains visible in the post ...

The checkbox is not updating as anticipated

I'm currently developing a basic widget that allows the user to change the value of either the check box OR the entire div by selecting them. Below is the code I have implemented: $(document).ready(function() { $(document).on("click", ".inputChec ...

Angular 10 is displaying a message indicating that a font has not been

I'm facing an error in my Angular project when trying to add a font to the SCSS file. How can I resolve this issue? style.scss: @import "~@angular/material/theming"; @include mat-core(); $PWP-primary: mat-palette($mat-indigo); $PWP-accent: ...

Having trouble understanding why the border-radius attribute is not being applied to tables?

I've been trying to give the outer corners of tables a rounded appearance in HTML/CSS, but I can't seem to get the border-radius property to work properly. After inspecting the elements in Chrome's computed section, I noticed that the eleme ...

Please ensure that all default tags (checkboxes) have a data-id or id assigned to them

When attempting to update todo tags using patch, I encountered an issue where the id or data-id is missing from pages created by Onenote with default todo tags. How can I target the element with patch? For example, on this page, the data-tag="to-do" does ...

Choose a Vue filter according to the variable selected

My Current Table Dilemma Creating a table from a 2D array in Vue2 has been successful for me, as I've managed to display all the values correctly. However, I am facing issues with formatting. The template code is structured like this: <table> ...

Adjust the baseline of the text within the <li> element by moving it 2 pixels upwards

My webpage menu is set up with inline lis within a ul. Each li has a colored border and contains an a element. I want to change the color of the text inside the a element and move it 2 pixels up when hovering over it without affecting the li border. How ...

Is the canvas refusing to disappear?

My HTML5 Canvas element is not disappearing as expected. I wrote a timer function to hide the element when the timer hits 0. I tested this using an alert flag and it worked perfectly. Problem: if (TotalSeconds <= 0) { ctx.clearRect(0, 0, canvas.w ...

Page width incorrectly set leading to unnecessary scrolling

Having a bit of trouble with this layout - while everything looks good, the page extends to the right with just a blank space. I've tried everything but nothing seems to work. .container.open-sidebar { position: relative; left: 240px; } #sidebar ...

What is the best way to extract specific content from HTML and display it within a specific HTML tag using

#!/usr/bin/env python import requests, bs4 res = requests.get('https://betaunityapi.webrootcloudav.com/Docs/APIDoc/APIReference') web_page = bs4.BeautifulSoup(res.text, "lxml") for d in web_page.findAll("div",{"class":"actionCol ...

Displaying or hiding table columns in Vue.js Element-UI el-table based on screen width: a step-by-step guide

Here is my code snippet for generating a table: <el-table :data="tableData" empty-text="No data to display :( " v-if="window.width > 855"> <el-table-column v-for="column in tableColumnsMd" :key=&q ...

SASS - centering timeline content vertically

I am a beginner in frontend development and I am currently using sass. I have created a custom timeline, but I need assistance in properly aligning the location with the year and timeline marker. Additionally, I would like to position the image description ...

What is the best way to position my header at the top of my navigation bar?

I am new to the world of HTML and CSS! My goal is as follows: https://i.stack.imgur.com/hmLNS.png This is my progress so far: https://i.stack.imgur.com/rav8P.png I am also looking to have the header fill the entire browser window and remain fixed, wit ...

The styling of Bootstrap CSS is not displaying correctly within the body of the webpage

I'm facing an issue where the content in the body of my page is not rendering correctly due to a problem with my bootstrap css. Specifically, the paragraph tag seems to be rendering inside the image tag even though both are within the body. @{ Lay ...

Code is not running in ReactJS

My challenge is to use canvas and script to draw a rectangle with one diagonal line. However, when I try to do so, only the rectangle appears on my browser. It seems like the script is not being executed. Here's the code: import React, { Component } ...

Unable to calculate height properly when using the formula height: 70% + 0px

My attempt to set the height of a div element to 70% using CSS3's calc() function has been unsuccessful. While specifying viewport height (70vh) works, I specifically need the height to be 70%. .scroll-inner-container { height: -moz-calc(70vh + 0 ...

Exploring the width of Bootstrap 5 Tab Pane content

My issue lies with the content width of my tab panels - specifically, it doesn't work well with columns. I am unable to divide a tab-pane as col-md-7 and col-md-5 (refer to the screenshot below). I am unsure of how to resolve this issue. <div clas ...

Place the background image of the parent element relative to the child element

I am struggling to position the background image of <body> relative to one specific child <div>. <body> <div>content</div> <-- place background image of body relative to this div <div>other content</ ...