在我的 Django 元素中,我尝试将 HTMl 连接到 CSS。我在网上查看了堆栈溢出的其他相关问题,但仍然无法将 html 和 css 链接在一起。我也是前端开发的新手。
这是我的代码(css 文件与此文件位于同一目录中):
<head>
<link rel="stylesheet" href="signup.css" type="text/css">
</head>
<div id="signuptext" class="pb-0"><span>Sign Up</span></div>
CSS:
#signuptext {
font-size: 30px;
}
收到错误:
Not Found: /accounts/signup/signup.css
更新:更改路径(href):
/accounts/templates/users/signup.css
更新代码:
<link rel="stylesheet" href="{% static 'signup.css' %}" type="text/css">
更新的 CSS(在主静态文件夹中):
#signuptext {
font-size: 30px;
}
我不明白这个错误,因为我的 css 文件与 HTML 文件位于同一文件夹中。 有人知道怎么了吗?谢谢。
最佳答案
<link rel="stylesheet" href="/accounts/signup/signup.css" type="text/css">
另外,使用类,更好,因为你可以重用它们。只有在需要用到js的时候才使用id
。
<div class="signuptext" class="pb-0"><span>Sign Up</span></div>
CSS:
.signuptext {
font-size: 30px;
}
关于HTML 未正确连接 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58613017/