My HTML file is linked to a CSS file, but the CSS doesn't seem to load when I use live-server.
Interestingly, the CSS works perfectly fine when I directly open the HTML file in a browser. The CSS file is located outside the directory where my HTML file resides.
When running live-server through an npm script with the command npm start
without any arguments, it displays all files in my workspace and the CSS loads if I click on the directory containing the main index.html
file. However, if I specify the path as an argument in the npm script, only the HTML file loads without applying any styles.
In my HTML file (index.html), the link to the CSS file looks like this:
<link rel='stylesheet' type='text/css' href='../styles.css'>
In my package.json file:
"start": "live-server home"
Using the above configuration doesn't load the CSS. Only
"start": "live-server"
actually works, as it shows the working directory in the browser. Then, I can navigate to the 'home' directory to view the HTML file along with the CSS styling applied.
When I run `npm start` from the terminal, the HTML file loads properly in the browser. However, for some reason, the linked CSS file fails to load. This is puzzling because the CSS link works as expected when opening the file directly in a browser. Is it necessary for the CSS file to be in the same directory as the HTML file?