为什么我的CSS文件中的背景图片没有应用到我的网页?

时间:2015-03-23 21:39:02

标签: html css background-image

的index.html

<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="style sheets/style1.css" type="text/css"/>
        <title>Colorado National Parks and Monuments</title>
    </head>

<body>
    <h1>Colorado National Parks and Monuments</h1>
    <br/>
    <h2><img src="images/Colorado Parks.gif" alt="Button to Colorado Parks webpage"/></h2>
    <h2><img src="images/Colorado Monuments.gif" alt="Button to Colorado Monuments webpage" usemap="#goToColMons"/></h2>
    <h2><img src="images/Spotlight Park.gif" alt="Button to Spotlight Park webpage"/></h2>
    <h2><img src="images/Places to Stay.gif" alt="Button to places to Stay webpage"/></h2>

    <map name="goToColMons">
        <area shape="rect" coords="0,0,139,40" href="colorado_monuments.html"/>
    </map>

    <p>Colorado offers unequaled natural mountain scenery, abundant wildlife,</p>
    <p>and more outdoor activities than you can imagine. The name Colorado</p>
    <p>comes from the Spanish word “colorado” which means “reddish</p>
    <p>color.” On August 1, 1876, President Ulysses Grant proclaimed</p>
    <p>Colorado the 38th state.</p>

</body>

</html>

style1.css

body {
background-image: url('images/backg.jpg');
}

h1{
text-align: center;
font-family: sans-serif;
color: brown;
}

index.html的位置与文件夹图片&amp;样式表。

图像backg.jpg的位置位于图像文件夹中。

style1.css的位置位于样式表文件夹中。

2 个答案:

答案 0 :(得分:1)

body {
background-image: url('../images/backg.jpg');
}

我认为路径是错误的,你必须去一个。

答案 1 :(得分:1)

CSS文件中的路径是相对于该文件的,因此您的网址应如下所示......

body {
background-image: url('../images/backg.jpg');
}