为什么我的css找不到?

贾瓦德·德哈贝

我已将我的 css 文件附加到我的 html 文件中。然后我在 node js 中使用 express 运行并打开页面。但是,当我通过节点 js 运行网络服务器时,css 文件不会打开。
html(show.ejs)

<html>
<head>
<link rel="stylesheet" type="text/css" href="assets/css/style.css" media="screen" />
</head>
  <body>
    <h1> Value is <%= detail %></h1>
  </body>
</html> 

节点js

//required npm
var express = require('express');//express 4.*

var path = require('path');

// define app
var app = express();

// set up template engine
app.set('view engine', 'ejs');


//static files
//app.use('/static', express.static('/public')); //not working
app.use('', express.static(path.join(__dirname, 'public')));  //not working
//app.use(express.static(__dirname + '/public'));  //not working
//app.use('/public/assets', express.static('public/assets'));  //not working

app.get('/show/:id', function (req, res) {
    res.render('./panel/show', {
        detail: req.params.id ,
    });

//port
app.listen(3000);

我的项目文件夹

节点模块

意见

控制板

显示.ejs

上市

资产

css

样式文件

应用程序.js

包.json

尼基尔·萨瓦利亚

通过输入<link rel="stylesheet" type="text/css" href="assets/css/style.css" media="screen" />您正在尝试assets在您的公共目录之外找到该文件夹。

因此,当您/找到public在 express 服务器中静态定义的目录时。

<html>
<head>
<link type="text/css" href="/assets/css/styles.css" rel="stylesheet">
</head>
  <body>
    <h1> Value is <%= detail %></h1>
  </body>
</html>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章