问题描述
我是一个初学者,正在尝试创建一个网站并将 CSS 样式表存储在与 HTML 文件不同的文件夹中,但在同一目录中.
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.
我把它放在我的 HTML 的标题标签中:
I put this in the header tag of my HTML:
<link rel="stylesheet" type="text/css" media="screen" href="./style/stylesheet.css" />
但它不起作用.
该文件与我的 HTML 位于同一目录中的style"文件夹中.
The file is in the folder "style" in the same directory as my HTML.
当我将 CSS 文件和 HTML 文件放在同一个文件夹中并以相同的方式链接到它时,它可以工作href="stylesheet.css"
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:
推荐答案
该文件与我的 HTML 位于同一目录中的style"文件夹中.
The file is in the folder "style" in the same directory as my HTML.
不,不是.
图像显示 HTML 位于名为 LoggedIn
的文件夹中,CSS 位于名为 style
的文件夹中,但 style
为 not 在 LoggedIn
内.它是 LoggedIn
的同级目录,而不是它的子目录.
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.
所以在进入style
之前,你需要上一层楼.
So you need to go up a level before you go down into style
.
将 ./
(当前目录)替换为 ../
(父目录).
Replace ./
(the current directory) with ../
(the parent directory).
这篇关于(HTML) 在其他文件夹中链接 CSS 样式表但同一目录不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!