我在方括号中的代码未读取我调用的文件

问题描述 投票:1回答:2

我的台式机(在Mac上工作)上有一堆文件夹,我试图将各种文件调用到style.css文件和index.html文件中。有人希望向我解释如何将文件调用到我的代码中,而不是尝试对我的所有目录/代码进行复杂的解释?文件树层次结构如何在中工作?例如,如果我有三个文件夹:

  • 父文件夹/文件夹A /代码/ index.html
  • 父文件夹/文件夹A /图像/cat.jpg
  • 父文件夹/文件夹B / MoreImages / dog.jpg
  • 父文件夹/文件夹C / MoreCode / style.css

如果我的索引文件在文件夹A中,并且我想调用cat图像,我应该写文件夹A / Images / cat.jpg还是只需要写Images / cat.jpg?

并且要调用文件夹A之外的项目,因此在文件夹B和C中,我是否需要在中执行任何操作才能使了解这些文件夹的位置?例如,我试图将style.css表调用到index.html文件中。我是通过简单地编写Folder C / MoreCode / style.css来实现的。我还双击了style.css工作表,将其添加到“括号”中的工作文件列表中。但是,我的html文件仍未读取我的样式表。

html css adobe-brackets
2个回答
0
投票

[<img src="picture.jpg"> picture.jpg与当前页面位于同一文件夹中

<img src="images/picture.jpg">

picture.jpg is located in the images folder in the current folder

<img src="/images/picture.jpg">

picture.jpg is located in the images folder at the root of the current web

<img src="../picture.jpg">

picture.jpg is located in the folder one level up from the current folder

要调用样式表,因为它向下2级,请添加三个时间段,然后/依次输入文件夹名称和样式表名称。

直接来自W3schools:https://www.w3schools.com/html/html_filepaths.asp


0
投票

目录结构从文件的当前位置开始工作。例如,如果您的index.html文件位于以下位置:

Parent Folder/Folder A/Code/index.html

并且您想要调用猫的图像,您将使用以下地址:

../Images/cat.jpg

../-移出当前目录(代码),回到上一个目录目录(文件夹A)。

Images/-查找名为Images的目录。

[cat.jpg-显示cat.jpg图像。

同样,要加载样式表,您需要向后移两个目录。从当前目录Code/中移出,然后从Folder A/目录中移出,回到Parent Folder/目录。因此,您将使用:

../../Folder C/MoreCode/style.css

我还将从您的目录名称中删除空格,因为这可能会导致问题,因此,请代替Parent Folder/Folder A/,将其更改为ParentFolder/FolderA/

© www.soinside.com 2019 - 2024. All rights reserved.