Conceal excess of video background overflow

My goal is to prevent the video from overflowing the container by maintaining its aspect ratio and hiding the excess portion that does not fit within the container. I have attempted using overflow: hidden; on the container, but it doesn't seem to work as expected.

Essentially, when viewing the site, I want the video to retain its aspect ratio without resizing while only displaying what fits within the container.

    <header id="welcome-section">
        <div>
            <p id="hello">Hello, my name is</p>
            <h1 id="ryan">Ryan Thacker</h1>
            a href="#section-a" class="button">Learn More</a>
        </div>
        <video autoplay muted loop id="bgVideo">
           <source src="images/Beach.webm" type="video/mp4">
        </video>
    </header>
    #welcome-section {
      background-size: cover;
      background-position: center;
      height: 100vh;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding: 0 20px;
      text-align: center;
      color: white;
      font-family: "Montserrat", sans-serif;
    }
    
    #bgVideo {
      position: absolute;
      top: 0px; 
      left: 0px; 
      min-width: 100%; 
      min-height: 100%;
      z-index: -1;
    }

Answer №1

To help prevent horizontal overflow, try applying the CSS rule overflow-x: hidden to the body element.

Answer №2

Hey there! It seems like you were looking to set the video width equal to the width of your #welcome-section. By incorporating some CSS adjustments, I managed to fix this issue.

html, body {
  width: 100%;
  margin: 0;
}

#welcome-section {
  box-sizing: border-box;
  width: 100%;
  background-size: cover;
  background-position: center;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  text-align: center;
  color: white;
  font-family: "Montserrat", sans-serif;
}

#bgVideo {
  width: 100%;
  position: absolute;
  top: 0px;
  left: 0px;
  min-width: 100%;
  min-height: 100%;
  z-index: -1;
  box-sizing: content-box;
}

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

"There seems to be an issue with the KeyListener function in

The error I'm encountering is: index.html:12 Uncaught TypeError: Cannot read property 'addEventListener' of null I'm unsure about what went wrong. The intention behind the code was to store the result of the selected radio button into a ...

What is the method to align my text to the top of the page?

I'm working on a 4-column page and trying to insert content. Everything is functioning properly except for getting my first div to align to the top in inline-blocks. As a newbie, I feel like I must be overlooking something simple. (I've tried usi ...

Switching Unicode icon when element is clicked

My form has two inputs - one for text input and the other for submitting, like a button. I have added an icon to the submit button and want it to change when clicked. <input class="searchBtn" id="submit" name="submit" type="submit" value="&#xf002"& ...

Show the TEXT in the upper right corner

I'm currently using bootstrap CSS. I have a header page where all the page links are displayed, and I want to show the LOGGED IN USER'S NAME IN THE TOP RIGHT CORNER. <li class="nav-item"><a class="nav-link text-dark"& ...

CSS: ways to set a maximum height for a datalist container

Hello, I have a datalist with over 100 options and I would like to set a maximum height for it to ensure the design looks tidy. Can anyone please help me out with this? Thank you! <input type="text" list="suggestions" class="f ...

Scrape the webpage to locate the HTML node containing the final page number

Currently, I am delving into the world of web scraping and have set up a personal challenge for myself: to extract all the titles from a recipe website. You can find this exercise at . (My inspiration came from reading this post: ). Specifically, my goal ...

CSS selector rules are being ignored by the hover effect on SVG stop-color

Attempting to create a hover effect on a link with an SVG as a child element. Desire to alter the stop-color of the svg when hovering over the link. Encountering issue where all the SVG icons change stop color when hovering specifically over the first .li ...

How to activate a function or event upon closing a browser tab with JavaScript

How can a function be triggered when a user closes the browser tab, preventing it from closing immediately and instead displaying a popup prompting the user to either proceed to another page or close the tab? Scenario: In the event that a user attempts t ...

Enable a single column to scroll until the content is fully displayed, and then stay in a fixed position

My HTML content consists of two columns, with the first column being a sidebar that should have limited content. The second column holds the main content and can span several pages. The desired functionality is for the first column to scroll until the end ...

Displaying a few squares with Angular Material's mini buttons surrounding them

Problem with displaying squares when using Angular material mini buttons in my Angular 7 project. Any suggestions on how to fix this issue? Thanks. Please take a look at the issue below: https://i.sstatic.net/VaGDV.png Here is my code: component.html ...

PHP and mysqli combine to create a versatile image slider with changing images

I am looking to implement an image slider that can be updated by the admin using php and mysqli. The admin should have the ability to easily add or remove images as needed. ...

Images do not seem to show up on GitHub pages

I've been grappling with the issue of images not showing up on Github pages for two days now. I've scoured the internet and attempted all suggested solutions. Could you please provide me with a step-by-step guide, and if possible, include a scree ...

Difficulty in locating elements within ngView-loaded elements using jQuery [AngularJS]

I am attempting to retrieve the offset().top of an element <div class='profile'></div> located within a ngView controlled by app.js. However, I encounter an error in the console: Uncaught TypeError: Cannot read property 'top&a ...

Personalized HTML ProgressBar featuring indicators

As I explore options for creating a progress bar/timeline with the ability to add markings (white lines shown in the image below) upon clicking a button, I've looked into HTML5 canvas and custom jQuery solutions. I'm curious if anyone has any spe ...

The font type is glitched, Internet Explorer is displaying the incorrect font

Is there a problem here? Below is the additional CSS provided: @font-face { font-family: NeutraText-Book; src: url('../fonts/NeutraText/NeutraText-Book.eot'); /* IE9 Compat Modes */ src: url('../fonts/NeutraText/NeutraText-Book ...

Dual columns filling the entire page within a container

Is there a way for me to pass the background images dynamically through inline styles? I can achieve this easily with pseudo elements, but I would like the content of the right and left columns to be enclosed in a container. You can view my proposed soluti ...

What is the best way to refresh the content of an iframe when a link within the iframe is clicked?

In the code below, I am resizing the iframe based on its content: <html> <head> <title></title> </head> <body> <iframe src="http://page.html" id="iframeid" width="600" height="700" scrolling="n ...

Remove all styling applied through Javascript

If we consider the following scenario: var e = document.getElementById("someElement"); e.style.borderColor = "gold"; e.style.background = "yellow"; e.style.padding = "5px"; // more style changes made through javascript It's possible that additional ...

What is the best way to adjust column sizes, setting one with a minimum width while allowing the other to expand to accommodate its content?

In the process of creating a user interface, I have included clickable cards that reveal a detailed panel when clicked. The detail panel is set to a minimum width of 900px and should adjust to the remaining space between the cards and itself. The column ...

Tips for managing the dimensions of a select element in bootstrap

I need assistance with adjusting the width of select tags in my form so that they align properly with the text boxes above. Here is the HTML code: <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/& ...