Maximize a video to fit the complete dimensions of the screen's height and width

Issue :

  • I am facing an issue where I am trying to make a video fill the entire screens height and width, but for some reason it is not filling the container I have wrapped around it.

  • The <video> is wrapped inside a <div> with the following CSS styling:

Snippet :

 videoContainer: {
       height: '100vh'
    },
    video: {
       objectFit: 'cover'
    }

Answer №1

Here is another potential solution for your problem!

html.body {
  margin: 0px;
  height: 100%;
  width: 100%;
  position:relative;
}

video {
  height: 100vh;
  width: 100vw;
  object-fit: fill;
  position: absolute;
  top: 0px;
  right: 0px;
  bottom: 0px;
  left: 0px;
}
<video autobuffer controls autoplay>
  <source id="mp4" src="http://grochtdreis.de/fuer-jsfiddle/video/sintel_trailer-480.mp4" type="video/mp4">
</video>

Answer №2

.videoElem {
    position: absolute;
    width: 100%
}
.container {
    width: 600px;
    height: 400px;
    position: relative;
}

<div class="container">
  <video autoplay muted loop id="myVideo">
    <source src="http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4" 
type="video/mp4">
  </video>
</div>

Answer №3

Give this a try! Press the 'Run code snippet' button, then select 'Full page'.

#myVideo {
    position: fixed;
    left: 0;
    top: 0;
    min-width: 100vw; 
    min-height: 100vh;
}
<video autoplay muted loop id="myVideo">
  <source src="http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4" type="video/mp4">
</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 Vue application is unable to expand to 100% height when using a media query

Hello everyone, I'm currently using my Vue router for multiple pages, and I'm facing an issue where setting the height of the main container to 100% within this media query is not working as expected: @media screen and (min-width: 700px) { #sig ...

Checkbox customization that shifts position when clicked

I seem to be missing something as I can't seem to find a solution for this particular issue. I have implemented custom checkboxes on a list of sentences. Initially, they appear fine, but once you check the first checkbox, it shifts its position. I am ...

Optimizing Safari for the Best Screen Size Experience

I seem to be encountering issues with optimizing my website. Everything appears to be working correctly in terms of widths, heights, margins, etc., on my laptop. However, when I view the site on an iMac or any other computer with a larger screen size, the ...

Rails inline form

My Rails project has a navigation bar set up like this: <nav> <%= link_to "Home", root_url %> | <%= form_tag "/posts", :method => 'get' do %> <%= search_field_tag 'search', nil, :placeholder => ...

how can I modify the css style of an html element only when a specific sibling is present?

After searching through the MDN CSS documentation, I was unable to find any Combinators that can target the specific element I want to style. /* second-span red when first-span is present */ [first-span] ~ [second-span] { color: red; } /* firs ...

Functionality of inline forms on medium-sized screens

My inline form is not aligning elements correctly on medium screens. When the screen size reaches 666px, the form splits into 4 rows as shown in this bootply. The problem arises with the second row when the screen size is less than 660px. It only display ...

Can a submit button be created that integrates both a radio button and submission functionality?

Is there a way to combine a radio button and submit button into one element for submitting the value just with a click? Currently, I have a radio button and a separate submit button in my code, but I want to streamline it. This is the current code snippet ...

Is there a way to have the collapsible content automatically expanded upon loading?

I came across a tutorial on w3school (https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_collapsible_symbol), which demonstrates collapsible content hidden by default. The code snippet from the link is provided below. Can someone assist me in cha ...

What is the best way to position an element to the right of other elements within a div?

My goal is to style my button like this : desired look However, I'm unsure of the necessary steps to achieve this. Here is my HTML code : <div class="content" *ngIf="loading==false" > <div class="product" ...

Ways to ensure a row of floated images within a <div> container adjusts its size in sync with the browser

Struggling to resize four images inside a div as the browser window is resized? Frustrated that when the window is too small, the last image moves to the next row? Want them all to stay in one row? Despite searching for solutions, adjusting max-widths to 2 ...

Creating HTML elements using JavaScript

Below is the code snippet in question: function getAllRecipes(){ $.ajax({ type: "GET", url: "https://api.npoint.io/7493fda05b8038212eed", beforeSend: function() { $("#AllRecipe").html('Fetching...') }, success: func ...

Is it possible to fix the horizontal scrolling in Safari on an iPad?

Is there a method to prevent horizontal scrolling on Safari in iPad using JavaScript, CSS, or HTML? I added the following meta tag to try and adjust the viewport: <!-- Mobile viewport --> <meta name="viewport" content="width=device-width, ini ...

Utilizing functions for object creation in JavaScript

Having trouble with creating a function that automatically generates an object and then alerts its properties. Can't seem to get the alerts when I click the button. Any assistance would be appreciated. <html> <head> <s ...

encountered net::ERR_EMPTY_RESPONSE while attempting to locate a CSS file within an AngularJS directive

Every time my webpage attempts to access the css file from a directive, I encounter a net::ERR_EMPTY_RESPONSE. I have implemented door3's on-demand css feature, which allows for lazy loading of css files only when necessary. This feature works flawle ...

Step-by-step guide on using the input tag to embed videos

I'm trying to embed a YouTube video using an iframe with an input tag, but for some reason, it's not working. Can you help me find the mistake? Here's the URL I entered: https://www.youtube.com/embed/G20AHZc_sfM This is the code in the body ...

An XPath expression to locate a descendant element relative to an ancestor element higher up in the hierarchy compared to

<oc-resume-upload> <div data-test="resume-upload-container" class="form-section"> <div class="flex flex-column"> <h2 class="form-section-header form-section-header--required&qu ...

Is it feasible to share HTML5 media captures and display them in real-time on another page within the website?

Recently, I just learned about the html5 media capture API and I am excited to start experimenting with it. One thing that caught my attention is capturing the camera on the same page, but I haven't come across any information about streaming through ...

What is the best way to send an observable with parameters through @Input?

The objective is to transfer an http request from Component 1 to Component 2 and initialize its parameters on Component 2. Here is a pseudo code representation of my approach: Component 1 HTML <app-component-2 [obs]="obs"></app-component-1> ...

Optimal method for storing website information in a database through Django while utilizing a singular template for all web pages

I'm in the process of creating a website where the majority of the content will have a similar format and layout. I plan to use a single template for each post, with the actual content being stored in a database. The content will consist of HTML para ...

Customize PrimeNG component styles

Utilizing the PrimeNG OverlayPanel for a dropdown click feature, I am encountering an issue with moving the default left arrow to the right position. Despite trying various solutions, I have reached a dead end. Would you be able to provide me with some fr ...