Adjustable Video Size and Parent Container Vertical Space

Here is the code snippet I am working with:

.jumbotron {
  position: relative;
  z-index: -101;
  overflow: hidden;
  height: 500px;
  background: red;
}
.jumbotron video {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  z-index: -100;
}
.video-content {
  text-align: center;
  color: #fff;
}
<div class='jumbotron'>
  <video autoplay loop class="fillWidth">
    <source src="https://ia800201.us.archive.org/12/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4" type="video/mp4" />
    <source src="video.ogv" type="video/ogv" />
    <source src="video.webm" type="video/webm" />Your browser does not support the video tag. I suggest you upgrade your browser.
  </video>
  <div class='video-content'>
    <h1>Welcome to the Site</h1>
    <p>This is just a test but it shows a background video</p>
  </div>
</div>

<div class='container-fluid'>
  <div class='row'>
    <div class='col-md-12'>
      <h2>Section Heading</h2>
    </div>
  </div>
</div>

I'm concerned about the responsiveness of the video background. As I reduce the viewport size, the video starts shrinking while the parent div remains larger, leading to an unwanted red background showing up.

How can I make sure that the parent div scales appropriately with the video size? I want the h2 tag to move right below the video when the viewport width goes below 480px.

You can view a demo on this issue in this link

Answer №1

You can use this solution to achieve your goal :)

.jumbotron {
    position: relative;
    height: 500px;
    overflow: hidden;
}

.jumbotron video {
    position: absolute;
    bottom: 50%; 
    right: 50%;
    -webkit-transform: translateX(50%) translateY(50%);
    transform: translateX(50%) translateY(50%);
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -1000;
    overflow: hidden;
}

Answer №2

Transform the fixed height to padding-bottom within the .jumbotron class

.jumbotron {
  position: relative;
  padding-bottom: 56.25%;
  /* 16:9 */
  height: 0;
  background: red;
}
.jumbotron video {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%
}
.video-content {
  text-align: center;
  color: #fff;
}
<div class='jumbotron'>
  <video autoplay loop class="fillWidth">
    <source src="https://ia800201.us.archive.org/12/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4" type="video/mp4" />
    <source src="video.ogv" type="video/ogv" />
    <source src="video.webm" type="video/webm" />Your browser does not support the video tag. I suggest you upgrade your browser.
  </video>
  <div class='video-content'>
    <h1>Welcome to the Site</h1>
    <p>This is just a test but it shows a background video</p>
  </div>
</div>

<div class='container-fluid'>
  <div class='row'>
    <div class='col-md-12'>
      <h2>Section Heading</h2>
    </div>
  </div>
</div>

Answer №3

It's a bit confusing to me. I tried adjusting the video dimensions to match the viewport size for maximum screen coverage while maintaining its aspect ratio.

.jumbotron video {
  ...
  height: 100vh;
  width: 100vw;
  ...
}

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

Trouble with launching Semantic UI modal

I have implemented a button using Semantic UI and set up a click event to open a modal when clicked, but nothing is happening. When I click on the link, there is no response. I'm unsure what the issue might be. Below is the code for the button: < ...

In AngularJS, the process of replacing text using a filter can be achieved by following

Currently in the process of learning Angular, but I've hit a roadblock and can't seem to find a solution. I have a website that provides USPS shipping options, and I need to replace the default text with my own. The vendor's option shows &ap ...

When an excessive amount of text is added, a column begins to resemble a row

As I work on developing a practice app that involves sending messages, I've encountered a styling issue when the message length exceeds a certain limit. My scenario includes a user profile picture with the message displayed alongside it. However, whe ...

Sideways scrolling carousel/slider

Currently, I am in the midst of a project page where my aim is to incorporate a horizontal scrolling project/image slider. Strangely enough, all my attempts thus far have failed to produce the desired outcome. This is the layout: the projects must transit ...

What is the best method for pulling specific tags from HTML in Android with Jsoup?

How can I use jsoup to extract the HTML tag (div id="content-body-14269002-17342313) from this specific link? Could someone kindly share a code snippet demonstrating how to accomplish this task? ...

Opencart admin URL customizer (Eliminate index.php?route="")

Is there a way to conceal the index.php?route="" & user_token="" links on my Opencart admin page? I would like it to display as something like admin/dashboard instead of admin/index.php?route=common/dashboard&user_token="" ...

Storing information in a database without the need for a page refresh using ajax in laravel

My form allows users to input multiple fields and save them to a database using AJAX. Below is the HTML for my form: <form id="paramsForms" method="POST"> {{csrf_field()}} {{ method_field('POST') }} <div class="modal-body" ...

Exploring the semantic-ui dropdown menu feature in Chrome

When I first started learning to code with semantic-ui framework, I noticed a difference in behavior in Chrome compared to other browsers. The pointing menu on the left element (such as the search box) breaks down in Chrome, whereas it displays correctly i ...

Organize a list using custom span values with JavaScript

<ul id="CoreWebsiteTopHeader_6_list"><li><a class="navigation" href="/seller"><span class="editableLinks" data-id="32638" data-sort="110">Seller</span></a></li><li><a class="navigation" href="/about">&l ...

When a StaticFiles instance is mounted, FastAPI will issue a 405 Method Not Allowed response

Running a FastAPI application has been smooth sailing until I encountered an issue. In my current setup, the application script is as follows: import uvicorn from fastapi import FastAPI from starlette.responses import FileResponse app = FastAPI() @app.ge ...

The nested navigation bar is not displaying properly below the main navigation bar

Hey there! I'm having a bit of trouble with adding a nested nav within my main nav. The issue is that the nested nav isn't aligning properly under the main nav. Take a look at this screenshot for reference. The nested nav seems to be shifted abou ...

Centering items in Bootstrap 4, while excluding the first element

.c-footer { background: #000; padding: 20px 0; color: #fff; } .c-footer__logo { display: inline; } .c-footer__link { color: inherit; } .c-footer__link a { color: inherit; } .c-footer__link a:hover { color: #fff; } ...

Utilizing Ajax to dynamically update the content of a div element

As a newcomer to Ajax, I am trying to use xmlhttprequest to dynamically change the content of a div by fetching HTML from different URLs. However, my code doesn't seem to be working as expected. Can someone help me identify what I might be doing wrong ...

Change the JavaScript code to output HTML rather than just plain text

I've created a small plugin for tinymce4 that adds an additional dropdown menu with a list of headers (e.g. h1, h2...). The issue I'm facing is that I'm trying to display these header elements with their corresponding styles (e.g. <h1> ...

Problem with layout design (utilizing float properties)

I'm curious why the paragraph content gets sandwiched between two floated divs. I'd like the paragraph content to appear below the header. Also, why aren't the line breaks showing in the paragraph? Check out this JS Fiddle link for referenc ...

How to Handle Date Formatting in Angular with Ionic

Utilizing the ionic framework to create a hybrid app with Angular, I have encountered an issue with a form that includes two input boxes: one for date and one for time. The date input's value is being saved in the database in this format: Tue Mar 24 ...

Using Vuejs v-for on inline elements can remove unnecessary whitespace

While iterating through an array (or object) with v-for on an inline element in VueJS, there is no whitespace rendered around the element. Consider the following example: <div id="app"> Vue Rendering<br> <a v-for="fruit in fruits" ...

In HTML, an important concept to understand is how float:left is necessary when the combined widths of child blocks equal

Apologies if my question seems redundant, I was having trouble finding the right search terms. Let's discuss a scenario with a parent <div> containing two inline-block children, each with a width of 50%. If we don't apply overflow: hidden ...

Ensuring image stays centered always

I have a logo image that I want to center regardless of window size. Despite trying auto margins, I haven't been successful in achieving this. The logo image needs to overlap the bottom of my navigation bar, which is positioned above the logo. HTML ...

Type within a customizable div element located within an iframe

When I switched to using iframe driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@id='ContentFrame']"))); I attempted two different methods, but neither of them worked. Approach 1: WebElement webElement = driver.findElement(locat ...