我的问题是尽管台式机上的所有功能正常运行,但是当我在手机上查看时,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%;
}
}
答案 0 :(得分:1)
您只需要对#bgVideo
使用以下CSS
#bgVideo {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
overflow: hidden;}
object-fit
属性在这里很重要。您可以了解更多
here