【问题标题】:How do you change the background on a div to an image in HTML?如何将 div 的背景更改为 HTML 中的图像?
【发布时间】:2020-11-11 12:13:14
【问题描述】:

我已经尝试了一些事情,但无法正常工作:我正在尝试为我的 div 提供背景图片。以下是我尝试过的一些事情以及我的代码的 sn-p。提前谢谢!

<div style="background-image: url('images\storefrontday.jpg');"></div>
<div style="background: color url('images\storefrontday.jpg')"></div>

我也尝试在外部 CSS 中添加背景,但无济于事。

  <section class="opening">
        <div style="background: color url('images\storefrontday.jpg')"></div>
        <div class="container-fluid"> 
            <nav class="navbar navbar-expand-lg navbar-dark"> 
              <a class="navbar-brand" href="images\logo.webp"> The Fish House & Grill</a>
              <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
         <span class="navbar-toggler-icon"></span>
        </button>

【问题讨论】:

  • 有什么问题? color 是什么?
  • 这些是在几个不同网站上向 div 添加背景图像的几种方法,但都不起作用。
  • 你能检查图片的路径是否正确吗?
  • 是的,路径是正确的。
  • 当您指定 background 属性时,您不应该需要 colorbackground: color url('images\storefrontday.jpg')

标签: html image background-image


【解决方案1】:

@pai.not.pi 你说的太对了。我正在做“复制相对路径”并粘贴在空间中。它正在做一个反斜杠而不是一个正斜杠。此外,不需要引号。问题解决了,吸取了教训。非常感谢您的帮助。我希望你有一个美好的一周!

.opening{
     border-style: double;
     background-image: url(images/storefrontday.jpg);
     background-size:100% 100%;
     background-repeat: no-repeat;
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多