问题
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