图片背景溢出问题:页脚Hero Video穿透解决方案咨询
Hey there! Let's break down what's going on here and fix that annoying video穿透 issue step by step—since you're new to front-end, I'll keep things clear and simple.
The Root of the Problem
Your .leaf-left image uses position: absolute, but its parent <footer> doesn't have a non-static position (like relative). That means the image is positioned relative to the entire document instead of the footer. So when you set top: 900%, it gets pushed way outside the footer's bounds, and the footer's overflow: hidden does nothing—absolute elements live outside the normal document flow, so the footer can't "clip" them. That's why the Hero Video underneath shows through.
Fix Steps & Modified Code
Here's a straightforward solution that keeps your image editable while hiding the video behind it:
footer { background-color: #fcfcfc; padding: 50px; width: 100%; height: 20%; font-family: 'Lato', sans-serif; font-weight: 200; position: relative; /* Critical: Makes footer the positioning parent for the image */ overflow: hidden; /* Now works to clip parts of the image outside the footer */ z-index: 10; /* Optional: Ensures footer stays above the Hero Video if needed */ } .footer-nav { margin-left: auto; text-align: center; } .leaf-left { position: absolute; width: 30%; height: auto; left: 80%; bottom: -50px; /* Adjust this value to control how much of the image hangs below the footer */ }
Why This Works
position: relativeon footer: Anchors the absolute-positioned image to the footer itself, so the footer's boundaries now apply to the image.bottom: -50px: Replaces the extremetop: 900%to push the image's bottom edge 50px below the footer (tweak the number until it looks right for your design).overflow: hidden: Now that the image is tied to the footer, this property will clip any part of the image that goes outside the footer's bounds—hiding the Hero Video behind it.z-index: 10: If your Hero Video has a higher z-index than the footer, this ensures the footer stays on top. It might not be necessary ifoverflow: hiddenfixes the issue, but it's a safe backup.
Best of all, this keeps your image in the HTML (so you can edit it in your block) instead of switching to a CSS background—exactly what you wanted!
内容的提问来源于stack exchange,提问作者Caitlin

