html - 将 HTML 链接到 CSS

标签 html css

好的,我正在尝试将我的 index.html 链接到 mystylesheet.css,但它不起作用?它在 CodeAcademy 上完美运行,但在 chrome 中运行时似乎不起作用。顺便说一下,我正在使用 Notepad++。当我说不起作用时,我的意思是 css 中的样式没有出现,例如背景颜色。这就是全部,我做错了什么吗?

index.html

<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="mystylesheet" href="mystylesheet.css"/>
<title>A$AP World</title>
</head>
<body>
<p>Please agree with the terms&conditions before entering.</p>
</body>
</html>

mystylesheet.css

body {
background-color: black;
}

p{
color:red;
}

img {
display: block;
height: 100px;
width: 300px;
margin: auto;
}

最佳答案

您的rel 属性应该是rel="stylesheet":

<link type="text/css" rel="stylesheet" href="mystylesheet.css"/>

SitePoint explains it nicely :

The rel attribute defines the relationship that the linked resource has to the document from which it’s referenced. In most cases, this resource will simply be "stylesheet", which means, not surprisingly, “the referenced document is a style sheet.”

关于html - 将 HTML 链接到 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19863514/

相关文章:

css - 在同一个 CSS 文件中使用两个 body

javascript - 如何从td中获取值

CSS - 等高列?

CSS 计数器无法在 <ul> 内递增

html - 当用户点击展开所有分组 ui 网格时拦截

javascript - 在铁路由器中添加背景颜色

asp.net - 如何在不访问代码的情况下将文档类型更改为标准模式?

html - 两个图像相对的 Z-index

javascript - 如何将引导按钮与输入复选框链接起来?

css - SASS/SCSS 内容函数