简体   繁体   中英

Css not working in express with ejs template engine

i am using express js with ejs template engine Here is my folder strcture

- public
----- css
---------- style.css
----- js
---------- script.js
- views
----- partials
---------- footer.ejs
---------- head.ejs
---------- header.ejs
----- pages
---------- index.ejs
---------- about.ejs
- package.json
- server.js

Now i want to add style css in "partials/head.js" file,how can i do this ? I tried with following codes but not working for me,Where i am wrong ?

<link rel="stylesheet" href="../../../public/css/style.css"> 
<link href="/css/style.css" rel="stylesheet" type="text/css">

this is your answer because in app.js you already defined the public directory from which you are serving the static files. Like css/js/image

app.use(express.static(__dirname + '/public'));

You tried with following codes i think working for u.

In link give href as ../../public/css/style.css

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM