express css仅在索引页上显示
出于某种原因,我的web应用程序只在索引文件上加载css,即使是静态的body和html元素也只在index.handlebar页面上设置样式。我曾尝试更改css位置、href链接等,但没有任何效果。 所以我的app.js文件看起来像这样express css仅在索引页上显示,css,node.js,express,Css,Node.js,Express,出于某种原因,我的web应用程序只在索引文件上加载css,即使是静态的body和html元素也只在index.handlebar页面上设置样式。我曾尝试更改css位置、href链接等,但没有任何效果。 所以我的app.js文件看起来像这样 const express = require('express'); //Other Consts const path = require('path'); const app = express(); // Load Routes const task
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
-公共
-css
-main.css
-img
-观点
-布局
-main.handlebar如果您位于/users这样的子路径中,那么它将尝试在/users/css/main.css中查找css
在CSS路径前面添加一个“/”以始终从基本路径引用样式表
如果您在/users这样的子路径中,那么它将尝试在/users/css/main.css中查找css
在CSS路径前面添加一个“/”以始终从基本路径引用样式表
尝试导入url(“文件地址”)头标签中的code>也可以尝试导入url(“文件地址”)代码>也在标题标签中我要去吊死自己。。。不管怎样,谢谢你,这解决了问题:我去吊死自己。。。不管怎样,谢谢,这解决了问题:D
<link rel="stylesheet" href="css/main.css">