HTML未访问CSS外部文件



学习CSS的开始阶段。处理一个项目,让我在外部、内部和内联中修改HTML文件。成功地完成了除外部任务外的所有任务。

HTML文件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Methods for Adding CSS</title>
<link rel=”stylesheet” href="styled.css">
<style>
p {color: white; background-color: green;font-size:18px}
</style>
</head>
<body>
<div>Style me via the external method!</div>
<p>I would like to be styled with the internal method, please.</p>
<button style=background-color:orange;font-size:18px;>Inline Method</button>
</body>

CSS文件

div {
background-color: red;
color: white;
font-size: 32px;
text-align: center;
font-weight: bold;
}

第8行是链接到外部文件的一段代码
HTML和CSS文件位于同一文件夹中。

我尝试在文件夹中从VSCode创建新的CSS文件,方法是ctrl+单击终端中的引用链接,然后从文件夹拖放到VSCode。还尝试了./styled.css../styled.css,从文件夹中打开css文件来验证其中的代码。在chrome dev工具中打开,网络,选择CSS。它不显示任何文件。有理由相信语法是正确的。我觉得HTML没有找到CSS文件,但不知道如何补救。

问题是第8行”stylesheet”中的引号错误。将引号字符更改为"stylesheet",它就会起作用。

请将双引号从"改为";并清除浏览器的历史记录。我希望它能正常工作。

如果一切都正确,请检查文件名和目录。尝试清除浏览器的缓存。

最新更新