gpt4 book ai didi

html - 将 HTML 链接到 CSS

转载 作者:行者123 更新时间:2023-11-28 04:01:10 25 4
gpt4 key购买 nike

好的,我正在尝试将我的 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/

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