What methods can be used to restrict video height within a <div> element?

Is there a way to ensure that the bucket-list.mp4 video stays contained within the video-jumbotron div? Currently, the video's height extends beyond the bottom of the page depending on screen size, rather than being cut off and confined within the

<div class="video-jumbotron">
, which is the desired outcome in this scenario.

https://i.sstatic.net/vsSW4.png

Check it out

<div class="video-jumbotron">
  <video id="bg-video" autoplay="true" loop='true'>
    <source src="/assets/bucket-list.mp4" type="video/mp4" />
  </video>
  <%= image_tag 'goal-setting-bucket-list-website.png' %>
  CHALLENGE WHAT YOU DO
  TO CREATE THE LIFE YOU WANT
</div>

# The bottom of the video overflows below this <div>
<div style="background-color: white;">
  Testing
</div>

CSS Styling

.video-jumbotron {
  padding-top: 25px;
  padding-bottom: 40px;
  margin-bottom: 20px;
}

#bg-video {
  top: 0px;
  left: 0px;
  right: 0px;
  position: fixed;
  z-index: -1;
  width: 100%;
}

Answer №1

If the video block (#bg-video) is set as fixed, it will not be dependent on its parent div .video-jumbotron and will instead be relative to the body.

To establish a connection between the video tag (#bg-video) and its parent (.video-jumbotron), we need to contain it within the parent's boundaries.

In addition to your existing styles, include the following modifications (changing #bg-video position from fixed to absolute):

.video-jumbotron {
    position: relative;
    overflow: hidden;
}

#bg-video {
    position: absolute;
}

With these adjustments, the parent div .video-jumbotron gains control and can guide the child element accordingly :)

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 divide a div by utilizing word wrap?

My CSS-styled div is pretty straightforward .text { text-transform: capitalize; color: #FFFFFF; background: #918a8a; opacity: 0.6; font-size: 2em; height: 80px; width: 200px; } It creates a grey box w ...

Adaptable div arrangement

Currently, I am working on a layout that includes a toolbar and a main div. In my design, the positioning of the toolbar should change based on the window's dimensions. If the Y axis is smaller than the X axis, the toolbar needs to be on the left side ...

How can I resize my image to match the dimensions of the navigation bar?

Is there a way for me to match the width of my navigation bar with that of an image? The issue I'm facing is that the original size of the image is 497 x 298px, and in order to stretch it across the full width of the page while maintaining margins of ...

Creating a dynamic CSS hover animation for an input element with jQuery to ensure compatibility with Microsoft Edge

I am facing an issue where I have a row of six to nine switches with the <input type="checkbox"> element, and each switch animates when hovered over. In this animation, the knob slides down, and both the knob and track fill with colors or gradients. ...

What is the best way to conceal the li elements that exceed a single line?

I have a unordered list containing product information as list items. My goal is to hide the list items that do not fit on a single line based on the screen size. Therefore, the number of products displayed should adjust depending on how many can fit on a ...

Image transformation not rotating the image

I'm having trouble making an image of an X rotate 180 degrees when it's hovered over. Instead of rotating, the image just moves up and to the right. What am I missing that's preventing this from looking like a smooth 180-degree spin? .bl ...

Creating a dynamic visual effect by changing the background color's opacity with each

Is there a CSS or Less solution to change the background color of all dynamically added or removed child elements with a gradual increase of opacity? ul li { list-style: none; font-size: 16px; text-align: center; font-weight: bold; margin: 3p ...

What is the best way to vertically center a div that has a fixed position and a specific width in pixels

Is there a way to center a fixed position div with a specified width of 300px, rather than in percentage? <div class="mainCont"> <div class="childCont"> </div> The childCont div has a fixed position and width of 300px. How can I ensur ...

Adjust the width of xAxis[0] and xAxis[1] in Highcharts to their default values

Hi there, I need some help with Highcharts. Is it possible to adjust the width of xAxis[0] and xAxis[1] as well as reset the offset of xAxis[1] at runtime? I have a chart with two x-axes that need to be resized to fit different sized divs. You can see an ...

The functionality of Bootstrap 5's modal-dialog-scrollable seems to be malfunctioning

I recently created a Student Add form using bootstrap 5 <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dial ...

Guide to aligning text vertically in a column alongside an image using Bootstrap 5

I have been using the Bootstrap 5.3.2 grid system for most of my website. I am trying to create a layout with an image on the left and text on the right. However, I am facing an issue with aligning the text vertically in the column. Is there a way to achie ...

Preventing Servlet Redirection in HTML: A Step-by-Step Guide

Is there a way to send data from an HTML web page to a server using a servlet without redirecting? <form method="post" name="customerForum" action="addCustomer"> <button class="btn btn-success" id="ad ...

I am experiencing difficulty scrolling down on my website. Can anyone offer suggestions on how to resolve this issue?

I'm having trouble scrolling on my website and I can't seem to figure out how to add more content. I've tried adjusting the height in CSS, but it didn't work. I'm new to web development and would appreciate any help! Maybe the issu ...

Updating HTML5 localStorage value upon a click

Currently, I have implemented a countdown timer using the provided code snippet. To prevent the count from resetting upon page refresh or reload, I am utilizing local storage. However, if there is an alternative solution to achieve this functionality, I wo ...

Include an Open OnClick event in the React/JSX script

We have a dynamic menu created using JavaScript (React/JSX) that opens on hover due to styling. My inquiries are: Instead of relying on CSS for the hover effect, where in the code can I implement an OnClick event to trigger the menu opening using Java ...

Connecting to a different HTML file functions smoothly on a local server, but encounters difficulties when uploaded to a web server

Here is the structure of my folders: updated /public twitter.html /styles styles.css /views index.html server.js package.json I have an index.html file that is linked to twitter.html. In the .js file, I am using Express and Node.js to link them ...

Divs should be of consistent and adjustable height

I am in need of a layout with three columns: left column (with a red background) center column (with a yellow background) right column (with a black background) This is the HTML structure I have in mind: <div id="container"> <div id="left_ ...

Retrieve the content of a specific HTML tag using JavaScript

Is it possible to extract the content of a specific HTML tag as a string or XML format? <body> <script src="jquery.min.js"> //var test = document.getElementsByTagName("input"); //alert(test[0]); $(document).ready(function ( ...

When the symbol "&" is placed within a parameter, it causes the URL to break

I am facing an issue with the character '&' in URLs. Within 3 strings, one of them contains the text with the character '&'. For example: "Monsters & Co." I need to use these 3 strings to pass them in a URL to another pag ...

What is the best way to incorporate the parallax effect into a v-carousel?

Currently, I have a "v-carousel" containing multiple images and now I am looking to incorporate a parallax effect into it, similar to "v-parallax". <v-carousel cycle height="600" hide-delimiter-background show-arrows-on-hover> <v-carousel-i ...