Home > database >  HTML Paths not working when opened outside of VSCode
HTML Paths not working when opened outside of VSCode

Time:05-21

I am learning HTML and i am keeping my secondary websites in /subwebsites/website.html

/ is the root folder containing also index.html:

File structure

However, opening the subwebsites anywhere outside of the VSCode live server browser makes the subwebsites not be able to find any stylesheet, other .html file or image anymore. It works with the index.html, but as soon as the website is contained in a subfolder it won't work anymore. I am sure it has to do with the way my paths are set but i tried everything I know off:

styles/main.css
./styles/main.css
/styles/main.css

picture showing how i added my paths

Thanks for your help in advance.

CodePudding user response:

In this case your html file need to go one level up. So for this you can easily use ../.

So just use this:

../styles/main.css ^_^

or

./../styles/main.css for your subwebsites.

But better to think to start use some kind of local server. For example, live-server for VSCode.

Also useful information for you:

  • / - root of the current drive

  • ./ - current directory

  • ../ - parent of the current directory

CodePudding user response:

you can use ~/styles/main.css or ../styles/main.css

../ is previous folder ~/ is root of server

The reason, may be server look for style inside this folder. And can't find it.

  • Related