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

Why is the background image in my CSS file not being applied to my webpage?

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 的位置与文件夹图像和样式表位于同一文件夹中。

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

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

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

我觉得路径不对,你必须上去。

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

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