Background video not resizing properly on mobile devices

Despite successful functionality on my desktop, the issue arises when viewing the website on my phone as the overflow-x: hidden property does not work.

To view the website in question, visit ryanjthacker.com. Additionally, you can access the complete code files on GitHub.

<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>

body {
    font-family: "Montserrat", sans-serif;
    overflow-x: hidden
}

#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 {
    position: absolute;
    top: 0px;
    left: 0px;
    min-width: 100%;
    min-height: 100%;
    z-index: -1;
}

@media only screen and (max-width: 768px) {
    #bgVideo {
        min-width: 50%;
        height: 50%;
    }
}

Answer №1

To achieve the desired effect on #bgVideo, you just have to apply the following CSS:

#bgVideo {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  overflow: hidden;}

The object-fit property plays a crucial role in this scenario. More details about it can be found here

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

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

Convert to cshtml and retrieve the logged-in user's identification

I'm completely new to using AngularJS. I recently developed a demo login app, but I'm facing an issue where the page doesn't render even when the login id and password are correct. Code: app.controller('MainCtrl', ['$scope&ap ...

Blazor combines the power of both C# and JavaScript by allowing them to be executed in a single

There is a button that triggers a JavaScript function: <button class="btn-orange btn" onclick="expand(this.closest('.profile'))">JavaScript</button> And there is another button that executes C# code and toggles ic ...

Tips for minimizing the gap between columns in vuetify's v-table

Trying to modify the width of a table and its columns within a v-table, aiming to create a more compact table but facing difficulties with all attempted adjustments. https://i.sstatic.net/fzJF4t16.png The objective is to minimize the table's width a ...

How can I make a div using jQuery fade in when an input field is in

I want to create a tooltip that changes its innerHTML and fades in when an input on my form is focused. Additionally, I need to check if the tooltip has been faded in as it initially loads faded out. In essence, I am looking to switch the tooltip content ...

Button press triggers the fadeIn function successfully, but the keypress event does not have the same effect

I'm currently facing an issue with two div elements on my webpage. I want only one of them to be visible at a time, depending on which key is pressed. If the 1 key is pressed, I want 'div1' to fadeIn (if it's not already visible) and fo ...

Utilizing a jQuery click event to modify the placement of a table

I have a request regarding the tables within the #middlebox. I would like to be able to rearrange the table positions by clicking on the list items. For instance, if the current order of the tables is starter -> soup -> seafood, clicking on the #seaf ...

The textbox content will disappear once it is transferred to the textarea

I am facing an issue with passing a value entered in a textbox to a text area. Whenever I execute my code, the value appears in the textarea momentarily before disappearing. Below is the HTML code snippet: Customer Name <input type="te ...

Tips for applying horizontal padding to the container-fluid class in Bootstrap 5

I'm struggling with the CSS code I wrote: .container-fluid{padding 3% 15%;} It's only adjusting the vertical padding to 3%, and there's no change in horizontal padding. #title { background-color: #ff4c68; } .container-fluid { pad ...

What is the best tool for combining CSS and SCSS code together?

My code is becoming hard to manage, so I need to consolidate some lengthy regular CSS statements like this: .aui #content .columns-1-2-equal .row-fluid #column-3 header { prop1 ...prop2 prop3 } into my current SCSS file. For instance, if I have a snippe ...

Ways to enhance the visibility of the active menu item background

Is there a way to customize the background color of an active menu item in Bootstrap 5 dropdown menus to look similar to Windows desktop applications? https://i.sstatic.net/VHmD04th.png Here is the code for creating a Bootstrap 5 dropdown menu, also avai ...

Adjust the color of the sidebar's list items when scrolling

How can I change the background color of left sticky sidebars li on scrolling? When scrolling through BMW, BMW's background color in the sidebar should turn green. Please refer to the code snippet provided below. The background color of the li ...

Regular Expressions for Password Validation in JavaScript

I'm seeking assistance in developing a regex pattern for a password. The password should consist of letters, numbers, underscores ( _ ), dollar signs ( $ ), and hyphens ( - ). It must be between 3 to 30 characters long. ...

Displaying a relative div on mouse hover over an HTML tag using React

In the section below, you will find the code snippet... <ul className="no-style board__list"> {Object.keys(today.books).map(function(id) { var refBook = today.books[id][0]; return ( ...

Following the recent update to IntelliJ IDEA 2022.1.3, the use of ::ng-deep has been marked

After updating the version of IntelliJ, I noticed that the ::ng-deep angular material selector is now marked as deprecated. Here's an example: <mat-form-field class="register-custom-select"> <mat-select formControlName="gende ...

Adjust the width of the graphics on both sides of the text based on the length of the text content

Is there a way to center an H1 tag between two graphics using CSS or jquery/javascript? The width of the H1 text will vary depending on the page. The dot on the left should remain at the edge of the site, and the line should extend to meet the edge of the ...

Need to specify the file type at the end of the URL for HTML input

How can I create a URL input form that requires the input to be a valid URL and end in a specific file type? Here is an example of my input: <input name="bg" placeholder="https://website.com/image" type="url"> Currently, the input field only restr ...

What is the best way to add a div to the bottom of a grid layout?

Here is the code I am working with: .my-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); grid-gap: 20px; } .item { background-color: #ddd; height: 300px; } <div class="my-grid"> <div class="ite ...

Basic ajax code for showing the title of a book

Recently, I delved into learning Ajax and decided to create a simple HTML page that showcases user input. The idea was to allow users to type in the name of a book, which would then trigger an Ajax call to fetch results from an array stored in a PHP file. ...

Is it possible to bring visibility to life through animation?

$(".leftNav").animate({"visibility": "visible"}, 200); I attempted the code provided above but unfortunately, it did not produce the desired result and I am unable to utilize .show() However, if the correct method involves using .show(), an alternative a ...

What is the best approach for managing the popstate event when the URL no longer exists?

When working with html5 popstate, I have two specific goals in mind. Instead of relying on plugins, I am utilizing these two methods: Push State: function contentLoaded(...) { ... window.history.pushState({ pageUrl: url }, url, url); ... } Po ...