视频背景无法自适应窗口高度及返回按钮无法点击问题求助(HTML/CSS)
Hey there! Let’s break down solutions for both of your video background issues—they’re pretty common hurdles, so I’ve got you covered.
The most likely culprit here is that your video or its container isn’t set to fully occupy the viewport height, or it’s failing to maintain aspect ratio correctly. Here’s a robust, tried-and-true fix:
First, ensure your root elements take up the full viewport without extra spacing:
html, body { height: 100%; margin: 0; padding: 0; overflow: hidden; /* Prevents unwanted scrollbars from appearing */ }
Next, set up a fixed container for your video that locks to all viewport edges:
.video-background-container { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; overflow: hidden; }
Finally, style the video itself to fill the container while preserving its aspect ratio (this is the critical piece):
.video-background-container video { width: 100%; height: 100%; object-fit: cover; /* Crops the video slightly if needed to fill the container without stretching */ }
object-fit: cover ensures the video scales proportionally and fills the entire container, no matter how the window is resized. You won’t get gaps at the top/bottom or sides anymore.
This almost always happens because the video container is sitting on top of your button in the z-index stack. Here’s how to fix it:
First, make sure your button is a positioned element (z-index only works on elements with position: relative, absolute, or fixed), then give it a higher z-index than the video container:
.return-to-site-btn { position: relative; /* Use fixed if you want it to stay in place while scrolling */ z-index: 10; /* Any number higher than the video container's z-index (defaults to auto, so 10 is safe) */ padding: 12px 24px; background: #fff; color: #000; /* Add other styling for visibility, like font size or border radius */ }
Double-check that neither the button nor any parent element has pointer-events: none set—this property would disable clicks entirely. If you find it, remove it.
That should resolve both issues! Let me know if you need to tweak anything for your specific layout.
内容的提问来源于stack exchange,提问作者methuselah

