You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

无法设置背景图片求助:指定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:

  1. 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
  2. Update your CSS with the correct URL:
    Replace your existing .home CSS 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;
    }
    
  3. Quick sanity checks:

    • Ensure your <section class="home"> isn't being blocked by the overlay navigation—you can add z-index: 0 to .home and z-index: 1 to .overlay-navigation if needed to manage stacking order.
    • Confirm parent elements of .home don't have overflow: hidden or height restrictions that might stop the section from filling the viewport.

Your HTML structure doesn't need any changes—only the background image URL in your CSS needs updating.


内容的提问来源于stack exchange,提问作者juhi

火山引擎 最新活动