html - 背景视频无法在移动设备上调整

标签 html css

我的问题是,尽管我的桌面上一切正常,但当我在手机上查看它时,overflow-x: hidden 不起作用。

这是有问题的网站,ryanjthacker.com这是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%;
    }
}

最佳答案

您只需要为 #bgVideo 使用以下 CSS

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

object-fit 属性在这里很重要。你可以了解更多 here

Applied CSS changes

关于html - 背景视频无法在移动设备上调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52427980/

相关文章:

html - 如何防止 HTML 源格式影响输出?

javascript - 如何在单击 'filename.php' 按钮时将一些值发送到 'Submit',即在下拉列表中选择的元素的值

jquery - 为什么 Jquery 不适用于 asp.net 中 LinkBut​​ton 的 CssClass 属性?

javascript - 使用样式过滤 js 查询

javascript - CSS 列数 - 水平对齐 - 砌体网格

javascript - 打开模态时无法滚动。

html - 如何在导航保持全宽时将导航项居中?

javascript - jribbble 不返回结果

Javascript - 循环 3 个函数,每个函数之间有延迟

javascript - jquery 按钮的类选择器没有响应