(HTML) linked CSS stylesheet in other folder but same directory doesn't work

放肆的年华 提交于 2021-02-08 11:08:43

问题


I am a total beginner and am trying to create a website and store the CSS stylesheet in a different folder that the HTML files, but in the same directory.

I put this in the header tag of my HTML:

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

but it doesn't work.

The file is in the folder "style" in the same directory as my HTML.

It works, when I have the CSS file and the HTML file in the same folder and link to it in the same way with href="stylesheet.css"

I have looked for other fixes, checked for typos, but it seems to be linked correctly already? I have also tried around different ways to type the path, but nothing works.

This is the way the folders are structured:


回答1:


The file is in the folder "style" in the same directory as my HTML.

No, it isn't.

The image shows that the HTML is in a folder named LoggedIn, and the CSS is in a folder called style but style is not inside LoggedIn. It is a sibling directory of LoggedIn not a subdirectory of it.

So you need to go up a level before you go down into style.

Replace ./ (the current directory) with ../ (the parent directory).




回答2:


According to the image structure you have there i think you should do something like this

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

This should work just fine



来源:https://stackoverflow.com/questions/52966506/html-linked-css-stylesheet-in-other-folder-but-same-directory-doesnt-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!