HTML和CSS背景图像不显示 [英] HTML and CSS Background-image is not showing up

查看:107
本文介绍了HTML和CSS背景图像不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经仔细检查过我的网址,以及文件的名称,但我似乎无法显示图片。为什么会这样?这里是我的代码(注意< p> 是在body标签内,我没有添加完整的代码,我只添加头和具体问题)。

I already double checked my URL, and the name of the files, but I can't seem to get the image to show up. Why is it like that? Here's my code (take note the <p> is inside the body tags, I didn't add the full code, I only added the head and the specific problem).

<html>
  <head>
     <title>Head First Lounge.</title>
      <link type="text/css" 
            rel="stylesheet" 
            href="stylesheet/style.css" 
            media="screen"/>
  </head>


<p class = "guarantee">
     Our guarantee: at the lounge, we're committed to providing you, 
     our guest, with an exceptional experience every time you visit.
     Whether you're just stopping by to check in on email over an 
     elixir, or are here for an out-of-the-ordinary dinner, you'll 
     find our knowledgeable service staff pay attention to every detail. 
     If you're not fully satisfied, have a Blueberry Bliss Elixir on us.
</p>        

下面是该部分的CSS规则

And here's the CSS rule for that part

.guarantee{         
        background-image: url(images/background.gif);
        font-family: "Geogia", "Times New Roman", Times, serif;
        border-color: black;
        border-width: 1px;
        border-style: solid;
        background-color: #a7cece;
            padding: 25px;
            margin: 30px;
            line-height: 1.9em;
            font-style: italic;
            color: #444;
}


推荐答案

>

Try this:

background-image: url(../images/background.gif);

没有 ../ 对于不存在的样式表文件夹中的图像文件夹。因此您必须返回图片文件夹所在的目录。

Without the ../ it is looking for an images folder inside your stylesheet folder which does not exist. So you have to go back a directory where the images folder is located.

编辑:您也可以缩短CSS样式,

Edit: You can also shorten up your CSS styles like so:

.guarantee{
    background: #a7cece url(../images/background.gif);
    border: 1px solid black;
}

这篇关于HTML和CSS背景图像不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆