我有一个 Express.js 元素,如下所示:
- 公开
- 图片
- javascript
- 样式表
- 路线
- index.js
- 观看次数
- authentication.html
- authentication.css
在 routes/index.js 我可以这样显示我的 html 文件:
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/../views/authentication.html'));
});
但是显示的文件没有包含在 authentication.css
中的样式.
然而,authentication.css
链接到 authentication.html
:
<head>
<meta charset="utf-8">
<link rel = "stylesheet" href = "authentication.css">
</head>
我试图移动我的 .css
到 public/stylesheets 文件夹并更改 <link>
标记指向新位置,但没有用。
我应该怎么做才能将我的 css 文件应用到相应的 html 文件?
最佳答案
因此,由于这篇文章,我找到了某种解决方案:https://stackoverflow.com/a/17911882/5016201 .
我刚刚在 app.js
中添加了这一行:
app.use(express.static(__dirname + 'views'));
它正确地显示了我的 html + css 文件,我不知道这是否是一个好的做法,但对于我正在做的事情来说已经足够了。
关于html - 如何在 express 元素中将 css 链接到 html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37610664/