[英]How do I link CSS and JS files to my HTML file for github pages?
I've just moved to github pages, and I have an index.html, an index.js and a style.css all in the same folder(master I believe).我刚刚转移到 github 页面,我在同一个文件夹中有一个 index.html、一个 index.js 和一个 style.css(我相信是 master)。 I've tried the following way to link the js and the css to the html:
我尝试了以下方法将 js 和 css 链接到 html:
<link rel="stylesheet" type="text/css" href="master/style.css">
<script src="master/index.js" type="text/javascript"></script>
However, it just doesn't seem to work.但是,它似乎不起作用。 In the middle, the CSS seemed to link once, but then after that when I tried to link the JS too, the whole thing stopped working again.
在中间,CSS 似乎链接了一次,但是在那之后,当我也尝试链接 JS 时,整个事情再次停止工作。 How do I fix this?
我该如何解决?
If all your files are in the same folder, I'm not sure you need to type folder's name.如果您的所有文件都在同一个文件夹中,我不确定您是否需要键入文件夹的名称。 Try to remove "master/" in your two lines of code.
尝试删除两行代码中的“master/”。
When you link stuff to your html file, the path is relative to that file.当您将内容链接到 html 文件时,路径是相对于该文件的。 So if style.css and index.js are in the same folder, you just link them by providing file names only.
因此,如果 style.css 和 index.js 在同一个文件夹中,您只需提供文件名即可链接它们。 If those file were in the folder above, you would link them by "../style.css" and "../index.js" If those file were in the subfolder (in relation to index.html), you would link them by "subfolder/style.css" and "subfolder/index.js"
如果这些文件在上面的文件夹中,您将通过“../style.css”和“../index.js”链接它们如果这些文件在子文件夹中(相对于 index.html),您将链接它们通过“子文件夹/style.css”和“子文件夹/index.js”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.