我的 CSS 根本没有被应用。我的错误是什么?

My CSS isn't being applied at all. What is my error?

我试图将 CSS 文件加载到 HTML 以设置样式,但 CSS 未加载。我将这两个文件放在同一个目录中

我有一个名为 Homepage.html 的 HTML 文件和一个名为 Homepage.css 的 CSS 文件:

<html>
    <title>
            Welcome to Sids World!
            <link rel="stylesheet" type="text/css" href="homepage.css">
    </title>

    <body>
        <div id="header"> <!-- menu here --> 
            This Site is Under Construction 
        </div>
        <div><!-- global division -->
        </div>
    </body>
</html>

此外,我的 CSS 文件(位于同一目录)具有以下代码:

body
{
    font-size:100%;
    background-color:red;

}
#header
{
    text-align:center;
    font-size:4em;
    font-family:sans-serif;
    background-color:blue;
}

我希望加载时整个网站的背景为红色,而我的文本周围的背景为蓝色,但这并没有发生。我在这里错过了什么?

两个文件的文件路径为:

C:\Sid\Rutgers\ComputerScience\SiteForDeploy\htmlfiles\Homepage.html

C:\Sid\Rutgers\ComputerScience\SiteForDeploy\htmlfiles\Homepage.css

如果有帮助,我正在使用 Sublime Text Editor 进行处理

Css url 区分大小写,因此您需要 <link rel="stylesheet" type="text/css" href="Homepage.css">

否则你的代码对我来说工作得很好http://jsfiddle.net/3deg1h05/

<html>
    <title>
            Welcome to Sids World!
            <link rel="stylesheet" type="text/css" href="homepage.css">
    </title>

    <body>
        <div id="header"> <!-- menu here --> 
            This Site is Under Construction 
        </div>
        <div>   <!-- global division -->
        </div>
    </body>
</html>

应该改为

<html>
    <head>
        <title>
            Welcome to Sids World!
        </title>
        <link rel="stylesheet" type="text/css" href="Homepage.css"/>
    </head>

    <body>
        <div id="header"> <!-- menu here --> 
            This Site is Under Construction 
        </div>
        <div>   <!-- global division -->
        </div>
    </body>
</html>

你的问题是双重的。首先,您未能为文档指定 <head> 部分。其次,您的 <link> 标签在您的 <title> 标签内。 <link> 标签应在 <head> 内,但不应在 <title> 内。更改为此,您会看到漂亮的颜色:

<html>
<head>
  <title>
    Welcome to Sids World!
  </title>
  <link rel="stylesheet" type="text/css" href="homepage.css">
</head>
<body>
  <div id="header"> <!-- menu here -->
    This Site is Under Construction
  </div>
  <div>   <!-- global division -->
  </div>
</body>
</html>