0

I am adding CSS and JS files to my node.js/express application using ejs templating engine. JS files are being applied but only the first included CSS file is being applied. All the files are being included but their styles are not being applied to the html other than the first one. If I import other css files into the first one only then they get applied to the html.

Adding via static method.

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

In html

<link href="css/custom.css" rel="stylesheet" title="custom" type="text/css" />
Nadeem
  • 1
  • 3
  • Check the console and network in browser developer tools, is there any error? – Rakesh Soni May 16 '17 at 12:19
  • No nothing related. The files are added and no errors on files but the css is not being applied to the elements. – Nadeem May 16 '17 at 12:56
  • Possible duplicate of [adding .css file to ejs](http://stackoverflow.com/questions/18629327/adding-css-file-to-ejs) – tyehia May 16 '17 at 15:01

1 Answers1

0

Assuming you put your file in public folder like below structure

 ./public
        /css
            /style.css

Then you should be able to view your file normally by this code

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

Make sure to remove style tags

tyehia
  • 257
  • 5
  • 16
  • I can only see the first included file's css applied to the html. Any css files added after the first one are not applied. There are no style tags in css files. If I import the css files into the first css file they get applied but not otherwise. – Nadeem May 17 '17 at 09:43
  • @Nadeem could you please share with me folders structure of your application and your html links – tyehia May 17 '17 at 10:09
  • app.js ./views /partials /head.ejs ./public /css /custom.css – Nadeem May 18 '17 at 11:33