gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 20:39:37 25 4
gpt4 key购买 nike

我试图将 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 进行处理

最佳答案

你的问题是双重的。首先,您未能指定 <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>

关于html - 我的 CSS 根本没有被应用。我的错误是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27750506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com