背景不工作的div [英] Background not working for a div

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

问题描述

我有以下HTML:

<html>
    <head>
        <title>
            Think in a NEW BOX.
        </title>

        <link rel="stylesheet" type="text/css" href="styles/default.css" />
    </head>
    <body onload="">
        <div id="content">
            <div id="header">
                <img src="images/title-1.png" /><img src="images/title-2a.png" /><img src="images/title-3.png" /></div><div id="fcontent">
                hi
hi
            </div>
        </div>
    </body>
</html>

...和以下CSS:

...and the following CSS:

div#fcontent{
        background-image:url('images/forground.png');
        width:100%;
        padding:0px;
        margin-top:0px;
        background-repeat:repeat-y;
    }

我的背景没有显示,为什么?

My background isn't showing up, why is this?

这里是所有的CSS,只是为了(这个问题可能在上面的CSS片段,但是):

Here is ALL of the CSS, just in case (the problem is probably in the CSS snippet above, however):

html, body {
        background-color:black;
        font-family:"arial bold";
        overflow:auto;
        text-align: center; 
        display: inline-block;
        color:white;
    }
div#content {
        width:792px;
        height:100%;
        padding:0px;
    }

div#header  {
        height:216px;
        width:100%;
        padding:0px;
        margin-bottom:0px;
    }

div#fcontent{
        background-image:url('images/forground.png');
        width:100%;
        padding:0px;
        margin-top:0px;
        background-repeat:repeat-y;
    }

*           {
        -webkit-user-select: none;
            -khtml-user-select: none;
            -moz-user-select: none;
            -o-user-select: none;
            user-select: none;
    }


推荐答案

图像是相对于CSS文件,所以如果你的CSS文件是在样式文件夹等,当前正在请求的图像必须位于/styles/images/forground.png。

Remember that the path to the image is relative to the CSS file so if your CSS file is in a "styles" folder etc, the image currently being requested must be located in /styles/images/forground.png.

如果您将网址的位置更改为绝对网址(例如从根目录),那么您可以避免此类问题。

If you change the location of the url to an absolute URL such as from the root, then you can avoid this kind of problem.

url('/images/forground.png');

或者您可能要跳出当前文件夹,然后进入images文件夹:

alternatively you might want to jump out of the current folder and then into the images folder:

url('../images/forground.png');

希望thant帮助。

这篇关于背景不工作的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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