无法设置背景图片求助:指定Unsplash URL无法生效
Fixing Background Image Not Loading Issue
Hey there, let's get that background image working for you! The root of your problem is that you're using a Unsplash page URL (https://unsplash.com/photos/cpLsWmMEa1Q) instead of the direct image resource URL. Browsers can't render a full webpage as a background image—they need the raw image file link.
Here's how to fix it:
Grab the direct image URL:
- Head to the Unsplash photo page you linked, right-click on the image itself, and select "Copy image address" (the exact wording might vary slightly by browser).
- For convenience, here's a pre-generated direct link for that photo:
https://images.unsplash.com/photo/cpLsWmMEa1Q?ixlib=rb-4.0.3&auto=format&fit=crop&w=1920&q=80
Update your CSS with the correct URL:
Replace your existing.homeCSS rule with this corrected version:.home { width: 100%; height: 100vh; position: relative; background-image: url(https://images.unsplash.com/photo/cpLsWmMEa1Q?ixlib=rb-4.0.3&auto=format&fit=crop&w=1920&q=80); background-size: cover; background-position: center center; }Quick sanity checks:
- Ensure your
<section class="home">isn't being blocked by the overlay navigation—you can addz-index: 0to.homeandz-index: 1to.overlay-navigationif needed to manage stacking order. - Confirm parent elements of
.homedon't haveoverflow: hiddenor height restrictions that might stop the section from filling the viewport.
- Ensure your
Your HTML structure doesn't need any changes—only the background image URL in your CSS needs updating.
内容的提问来源于stack exchange,提问作者juhi




