【问题标题】:Image background not loading with CSS图像背景未使用 CSS 加载
【发布时间】:2017-05-01 12:16:21
【问题描述】:

好的,我不能对任何其他问题发表评论,这就是我发布新问题的原因。

我已经尝试了this 答案和this 中建议的所有解决方案。

#head {
    text-align: center;
    font-family: roboto;
}

body, html {
    height: 100%;
}

.parallax {

    background-image: url('.../pics/parallax.jpg');

    height: 100%; 

    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}
  <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/animate.css">
    <link rel="stylesheet" href="css/text.css">
    <script src="scripts/jquery-3.1.0.min.js"></script>
    <script src="scripts/jquery.animate-color.js"></script>
    <script src="scripts/custom_scripts.js"></script>
    <title>Yadullah.me</title>
    </head>
    <body>
    <h1 id="head"> Hi there!</h1>
    
    </body>
    </html>

很简单吧?但由于某种原因,背景图片只是拒绝显示。
我尝试在同一个文件夹中使用我的 CSS、HTML 和图像,但没有成功。在不同的子目录中尝试过,没有成功。

我已经检查了文件名、扩展名和所有这些内容。尝试不带引号和不带引号的东西。甚至尝试了不同的图像。也尝试删除所有其他 CSS 文件,但没有任何效果。

【问题讨论】:

  • 看起来图像路径中的一个点太多了......
  • 要详细说明GCyrillus的评论,url('.../pics/parallax.jpg');应该是url('../pics/parallax.jpg');
  • @Santi 不幸的是,这也没有用
  • @YaddyVirus 告诉我们更多关于您的文件结构的信息。与您要检索的图像相关的 CSS 文件在哪里?
  • @Santi 我的 f: 驱动器上有一个名为 Yadullah.me 的文件夹,该文件夹有 3 个子文件夹,即 css、scripts 和 pics。 html 位于根文件夹中(即 Yadullah.me 文件夹)

标签: html css


【解决方案1】:

您的样式属性中有太多停靠点。您的 CSS 应如下所示:

.parallax {
    background-image: url('../pics/parallax.jpg');
    ...
}

【讨论】:

  • 只是为了排除显而易见的问题,您的 css 文件的名称是什么?它位于哪个文件夹中?
  • 它位于一个名为 css 的文件夹中。文件名是 text.css
【解决方案2】:
#head {
    text-align: center;
    font-family: roboto;
}

body, html {
    height: 100%;
}

.parallax {

    background-image: url('.../pics/parallax.jpg'); // In Here try put absolute URL or change .../ in ../

    height: 100%; 
width:100%; //and try add width
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

【讨论】:

    【解决方案3】:
    You can try add base tag for example like this 
    
    <!doctype html>
        <html>
        <head>
        <base href="http://YourSite.com/"> 
        <meta charset="utf-8">
        <link rel="stylesheet" href="css/animate.css">
        <link rel="stylesheet" href="css/text.css">
        <script src="scripts/jquery-3.1.0.min.js"></script>
        <script src="scripts/jquery.animate-color.js"></script>
        <script src="scripts/custom_scripts.js"></script>
        <title>Yadullah.me</title>
        </head>
        <body>
        <h1 id="head"> Hi there!</h1>
    
        </body>
        </html>
    

    【讨论】:

      猜你喜欢
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 2011-11-03
      • 1970-01-01
      • 1970-01-01
      • 2023-01-26
      • 2015-02-28
      相关资源
      最近更新 更多