【发布时间】:2020-07-09 03:11:27
【问题描述】:
这是我的堆栈
- 快递
- Ejs
- Sass(由 'npm install --save-dev sass' 安装 - 一个开发依赖项)
我收到一个错误
拒绝应用来自 'http://localhost:3000/css/style.css' 的样式,因为它的 MIME 类型 ('text/html') 不是受支持的样式表 MIME 类型,并且启用了严格的 MIME 检查。
我的 head 标签位于单独的部分文件夹中:
- 意见
- - 部分
- - - header.ejs
-- index.ejs
我的 CSS 也在另一个文件夹中
- 公开
- - css
- - - style.css
- - - style.css.map
- - - style.scss
我的头像是这样的:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Learn Web</title>
<base href="/">
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
我这样渲染我的索引:
app.get('/', (req, res) => {
res.render('index');
})
我尝试添加<base href="/">
我试图省略rel="stylesheet"
我尝试将type="text/css" 更改为type="text/html" - 它消除了错误但样式不适用。
提前谢谢你!
【问题讨论】:
-
这能回答你的问题吗? Stylesheet not loaded because of MIME-type
-
http://localhost:3000/css/style.css实际上是在为 CSS 文档提供服务,而不是例如HTML 错误消息? -
"我这样渲染我的索引:" — 你如何渲染 CSS?
-
("我这样渲染我的索引:" — 你如何渲染 CSS?) - 使用