Removing margins from the footer and header after adding a video background: A step-by-step guide

After implementing a video as the background of my HTML project, I noticed some margins appearing on the right side of the header and footer. Despite following advice to set "margin: 0" in my CSS for the Body element, the issue persists.

You can view the image link in the top right corner of the header.

https://i.sstatic.net/wBauP.jpg

I should note that this problem only occurs on this specific page after adding the video. Other pages do not exhibit this behavior.

.homepage_bg_video-container{
    position: relative;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    background-color: black;
}

.homepage_bg_video-container video{
    opacity: 0.4;
    position: absolute;
    width: auto;
    height: auto;
    min-width: 100%;
    min-height: 100%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#rights{
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    background-color: rgba(13, 13, 13, 0.9);
    height: 60px;
    padding-top: 1px;
    color: #ece5ea;
    border-top: #070606 1px solid;
}
<div class="homepage_bg_video-container">
    <video autoplay loop muted>
        <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
    </video>

</div>

<footer>
    <div id="rights">
        <p>Nits.SRL - Toate drepturile rezervate &copy; 2019</p>
    </div>
</footer>

Answer №1

To adjust the positioning of the video within the element's frame, you can utilize the object-position property. Additionally, the object-fit property allows you to control how the video's size is adjusted to fit within the frame:

video { object-fit: fill; } 

For more information, check out: https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit

EDIT

Give this a shot:

    body {margin: 0;}
    .homepage_bg_video-container {
        position: relative;
        max-height: 100vh;
        max-width: 100vw;
        overflow: hidden;    
        background-color: black;
    }
    video { 
    height: calc(100% - 62px); 
    width: 100%;
    object-fit: fill; 
        opacity: 0.4;
    }
    #rights {
        font-size: 16px;
        font-weight: bold;
        text-align: center;
        background-color: rgba(13, 13, 13, 0.9);
        height: 60px;
        padding-top: 1px;
        color: #ece5ea;
        border-top: #070606 1px solid;
    }
    <div class="homepage_bg_video-container">
        <video autoplay loop muted>
            <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
        </video>
    </div>
    
    <footer>
        <div id="rights">
            <p>Nits.SRL - Toate drepturile rezervate &copy; 2019</p>
        </div>
    </footer>

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

Element with absolute position does not expand along with scrollable content (over 100%)

In my popup window, the fade element is supposed to stretch to the full width of the screen. However, when the content exceeds 100% of the browser window height, the element does not extend to the full page height. If I set html, body { height: 100%; over ...

I have a parent DIV with a child DIV, and I am looking to use jQuery to select the last child DIV. The parent DIV has an

In my HTML code, I have a parent div called "allcomments_4" which contains several child divs with unique IDs (oneEntry), each with their own children. My goal is to locate and retrieve the content inside the last child of the parent node (lastComment) and ...

How can I eliminate unnecessary gaps in a CSS slider design?

Currently, I am in the process of learning CSS3 and attempting to create a purely CSS slider. Everything has been going smoothly until I encountered an unexpected padding or margin within my slider. After making some adjustments to the margins, the issue ...

Highlight columns and rows when hovered over in a striped table using CSS styling

I have successfully implemented a CSS-only method for highlighting table columns on hover from a tutorial I found at https://css-tricks.com/simple-css-row-column-highlighting/ However, I am encountering an issue with applying the highlight to striped tabl ...

Position the DIVs at the bottom of the TD

I'm having trouble aligning two DIVs within a table TD to the bottom of the table. Despite trying various alignment methods, the left DIV simply won't move. It's crucial for me to design this email responsively, ensuring it still displays co ...

What is the best way to send information from an MVC controller to JavaScript?

Being new to programming, I am working on 2 projects that function as client-server via Rest API. I am looking to create a column chart using data from a List of ID (participant) and Votes (Total votes) obtained from the server's connection with the d ...

Incomplete Loading of Google Maps

Let me clarify that the solutions I have come across so far have not been successful. I am attempting to display a modal alert with a basic Google Maps integration. Problem: Google Maps does not load completely. Snippet from my .js file: var map; functi ...

Issue with Magnific Popup lightbox functionality, and mfp-hide is ineffective

Hello everyone, I am new to stackoverflow so please bear with me as I navigate through it. Although I am still a beginner in HTML, CSS, and JS, I have been using them for work on occasion. Recently, I implemented Magnific Popup on a website I am working o ...

What are some ways I can make my content come alive on my website using the Tympanus examples

After spending hours searching for a way to add animation to my content, I finally found a technique that seemed promising. Despite following the same steps as outlined in the tutorial I found, I was disappointed to discover that there was no animation o ...

Tips for adjusting div content to fit a fixed height on all devices

Looking to adjust the size of the #left-content div based on the height of the window, while ensuring that all content is visible within the fixed #left-bg. However, when viewing on mobile or tablet devices, the content appears hidden. .left-bg{ backgro ...

AngularJS does not update values properly if there is a style applied to the parent container

I'm struggling to find the best approach to handle this situation. This is how my AngularJS code looks: <span class="something" ng-hide="onsomecondition"> {{value}} </span> .something{ text-align:left; padding:10px;} Issue: The value ...

JavaScript plugin designed for effortless conversion of JSON data to structured HTML code

I want to add this JSON data to an HTML element. [ { "website":"google", "link":"http://google.com" }, { "website":"facebook", "link":"http://fb.com" } ] Is there an easy way to convert this using a plugin ...

Experiencing problems with the calling convention in JavaScript

Here is a snapshot of the code provided: If the function testFields at Line:3 returns false, then the program correctly moves to Line:21 and returns the value as false. However, if testFields returns true, the program proceeds to Line:4, but instead of ex ...

Display line numbers in HTML/CSS cellsorIncor

Attempting to include row numbers in HTML/CSS. Below is the HTML code with React populating the rows: <table className="table table-striped"> <thead> <tr> {/*<th>ID</th>*/} ...

What is the purpose of the .php?action.. function?

I'm trying to understand the purpose of ?action=add&code= in the code snippet below. I've searched on Google, but all I found was information about HTML action attributes. <form method="post" action="index.php?action=add&code=<?php ...

Unique rephrased text: "Amongst a backdrop devoid of white,

In a div with a colored background, I noticed that adding an input element results in an unsightly border. <div class="input-group"> <input type="search" style="height:30px;"> </div> Is there a way to remove this border? ...

Can CSS rules be inserted outside of the Header section?

Question: Can CSS styles be declared outside the “HEAD” element of an “HTML” page ? While working within a CMS where access to the header tag is restricted, is there a method to include CSS rules within the <BODY> of the ...

The <form> element is giving me headaches in my JavaScript code

Trying to troubleshoot why my HTML pages render twice when I add a form with JavaScript. It seems like the page displays once with the script and again without it. Below is the basic HTML code: <form action="test.php" method="post"> <div class=" ...

Animating Text Around a Circle Using HTML5 Canvas

Can someone please help me figure out what is wrong with this code? It's not rotating as it should, and the text looks messed up. I've been trying to solve this problem for hours but can't seem to get it right. function showCircularNameRot ...

The CSS styles do not seem to be taking effect on the Bootstrap

Here's a snippet of code extracted from my website's html and css files. My intention is to make the navbar slightly transparent with centered links, but for some reason, the css styles are not applying correctly to the navbar. HTML <body ...