简体   繁体   English

如何链接位于另一个文件夹中的 HTML 文件中的 CSS 文件

[英]How to link a CSS file in HTML file which is located in another folder

My link looks like this我的链接看起来像这样

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

在此处输入图片说明

It is seen from the picture that path of the header.ejs file is /views/partials/header.ejs , while all.css file located at styles/all.css .从图中可以看出header.ejs文件的路径是/views/partials/header.ejs ,而all.css文件位于styles/all.css How to link these both files?如何链接这两个文件?

Change it to将其更改为

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

Explanation : If you go only one folder back from your header.ejs file, you are in the folder views .说明:如果您只从header.ejs文件返回一个文件夹,则您header.ejs文件夹views There is no styles folder stored there.那里没有存储styles文件夹。 So you need to go one more folder back.所以你需要再返回一个文件夹。

I think you need to use我认为你需要使用

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

to go up to the personal_website directory before going to /style/all.css在转到 /style/all.css 之前转到 Personal_website 目录

Hope this helps :)希望这有帮助:)

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

That should work.那应该工作。

  • Is the image in the same directory as the file referencing it?图像是否与引用它的文件位于同一目录中?
  • Is the image in a directory below ?图像在下面的目录吗?
  • Is the image in a directory above ?图像在上面的目录中吗?

By "below" and "above", I mean subdirectories and parent directories. “下面”和“上面”是指子目录和父目录。 Relative file paths give us a way to travel in both directions.相对文件路径为我们提供了一种双向传输的方式。 Take a look at my primitive example:看看我的原始例子: 在此处输入图片说明

Here is all you need to know about relative file paths:以下是您需要了解的有关相对文件路径的所有信息:

  • Starting with "/" returns to the root directory and starts there以“/”开头返回根目录并从那里开始
  • Starting with "../" moves one directory backwards and starts there以“../”开始向后移动一个目录并从那里开始
  • Starting with "../../" moves two directories backwards and starts there (and so on...)以“../../”开始向后移动两个目录并从那里开始(依此类推......)
  • To move forward, just start with the first subdirectory and keep moving forward要前进,只需从第一个子目录开始并继续前进

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM