html - 如何在 express 元素中将 css 链接到 html?

标签 html css express

我有一个 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/

相关文章:

css - 使用 css 变换在其父对象的宽度上为对象设置动画

node.js - 监听不同的 IP 地址

javascript - Express:将 res.json 作为参数传递时出错

node.js - 基于 REST/Web 的身份验证即服务是否可行?

javascript - 相对于 SCREEN 和 COL div 定位一个 div

html - 位置固定和 Internet Explorer

html - z-index Css 的问题

javascript - 在图片库中使用 jquery 自动水平滚动?

javascript - 筛选行并仅在屏幕上显示选定的行

jquery - 在滚动 Pane 周围环绕一个按钮