由于某种原因,我的网络应用程序只在索引文件上加载css,即使是静态的body和html元素也只在index.handlebars页面上设置样式。我试图改变css位置,href链接等,但没有任何效果。 所以我的app.js文件看起来像这样
const express = require('express');
//Other Consts
const path = require('path');
const app = express();
// Load Routes
const tasks = require('./routes/tasks');
const users = require('./routes/users');
const points = require('./routes/points')
// Public folder path
app.use(express.static(path.join(__dirname, 'public')));
//Index Route
app.get('/', (req, res) => {
res.render('index')
});
//About Route
app.get('/about', (req, res) => {
res.render('about')
});
// Use routes
app.use('/tasks', tasks);
app.use('/users', users);
app.use('/points', points);
const port = 4000;
app.listen(port,'0.0.0.0', function(){
console.log(`Server started on ${port}`);
});
文件树:
-public
-css
-main.css
-img
-views
-layouts
-main.handlebars <- css shows
-users
-login.handlebars <- css doesnt shows
-register.handlebars <- css doesnt show
-tasks
-index.handlebars <- css shows
-add.handlebars <- css doesnt show
-edit.handlebars <- css doesnt show
-users
-index.handlebars <- css shows
-add.handlebars <- css doesnt show
-edit.handlebars <- css doesnt show
-routes
-tasks.js
-routes.js
-users.js
-app.js
头部链接是:
<link rel="stylesheet" href="css/main.css">
答案 0 :(得分:1)
在标头标记中尝试@import url("File Address");
答案 1 :(得分:0)
如果你在/ users这样的子路径中,它会尝试在/users/css/main.css中找到css
添加&#39; /&#39;在CSS路径前面总是从基本路径引用样式表。
<link rel="stylesheet" href="/css/main.css">