无法设置背景图片

时间:2015-01-15 15:44:30

标签: html css image background sass

我正在研究一个项目,我试图添加一个背景img。 img确实有效,我可以在img src =“”中显示它。但是,当我试图将其添加为背景图像时,它无法正常工作。 如果有人可以帮助我,我会很高兴的!

html {


    body{
        background: url("images/background.png");

    }

    header {
        @include linear();

    }

    nav {
        text-align: center;
    }

    ul {
        padding-top: 200px;

    }

    li {
        display: inline-block;
        padding-right: 70px;
    }

    a {
        text-decoration: none;
        color: black;
        font-size: 20px;
        transition: all 1s ease;
        font-family: 'Elegant Lux';
        &:hover {
            color: gray;

        }
    }

}

1 个答案:

答案 0 :(得分:0)

看起来你有一个css块包裹着你的css的其余部分 - 尤其是html:

html { //你所有的CSS都在这里 }

确保它像这样分开:

html{

}

body{
    background: url("images/background.png");

}

header {
    @include linear();

}

nav {
    text-align: center;
}

ul {
    padding-top: 200px;

}

li {
    display: inline-block;
    padding-right: 70px;
}

a {
    text-decoration: none;
    color: black;
    font-size: 20px;
    transition: all 1s ease;
    font-family: 'Elegant Lux';
    &:hover {
        color: gray;

    }
}

另外,请确保图像路径正确。这将是css文件的实际信息,因此您可能需要使用“..”跳转目录。像这样:

body{
    background: url("../images/background.png");
}