【问题标题】:Can you add a background image in html? [duplicate]你可以在html中添加背景图片吗? [复制]
【发布时间】:2013-10-22 13:06:15
【问题描述】:

是否可以在 html 中添加背景图片?

这是我的小提琴,我需要它在“容器 div”上

我还需要背景在画布上伸展,我可以在 css 中这样做吗??

http://jsfiddle.net/7Gacp/3/

<div id="profile-container">
    <div id="fixed-header"></div>
    <div class="container" style="background: url("../../img/followers/followers-tabs.png") no-repeat 0 0px;"></div>
    <div class="sticky-header">This needs to be fixed when hits top of screen</div>
    <div class="img">needs to be smooth</div>
    <div class="img"></div>
    <div class="img"></div>
</div>

干杯

【问题讨论】:

  • 修正你的报价:"background: url("../../img/followers/followers-tabs.png") no-repeat 0 0px;""background: url('../../img/followers/followers-tabs.png') no-repeat 0 0px;"
  • 你能加个小提琴吗?
  • 来吧,这对于每个开发人员来说都是绝对基础的,而且它只是一个 10 秒的谷歌搜索。

标签: html css background


【解决方案1】:

background-image:url('image path'); 把这段代码放到你的css中,获取背景图片集。

【讨论】:

    【解决方案2】:

    像这样去掉双引号,改用单引号

    "background: url('../../img/followers/followers-tabs.png')
    

    【讨论】:

    • 你能加个小提琴吗?
    【解决方案3】:
    .container {
     height:300px;
     width:100%;
     background-image: url("Put your image link here.");
    }
    

    适用于内联样式:

    <div class="container" style="background: url('Put your image link here.') no-repeat 0 0px;"></div>
    

    Fiddle

    【讨论】:

    • 出于编程原因,我需要做内联css。
    • 对不起!我也忘了保存修改后的小提琴。以前的答案也可以,您只需将双引号更改为单引号。
    【解决方案4】:

    您需要从 url 中删除 qoutes

    <div class="container" style="background: url(../../img/followers/followers-tabs.png) no-repeat 0 0px;"></div>
    

    您可以使用 ',但 CSS 背景中的 url 根本不需要它们。

    这是固定的小提琴:http://jsfiddle.net/7Gacp/10/

    你可以使用散布背景

    background-size: 100% 100%;
    

    这是另一个小提琴:http://jsfiddle.net/7Gacp/11/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-24
      • 2017-06-15
      • 2014-01-26
      • 2020-10-18
      • 2017-05-22
      • 1970-01-01
      • 2020-02-06
      • 2017-05-10
      相关资源
      最近更新 更多