简体   繁体   English

如何将 CSS 和 JS 文件链接到我的 github 页面的 HTML 文件?

[英]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.

相关问题 从 HTML,CSS,JS 转换为 JSX, Z2C56C3602580420DFBEDZ,JS 时,如何在反应中链接我的 javascript 文件? - How do I link my javascript files in react when converting from HTML,CSS,JS into JSX, CSS, JS? 如何隐藏普通 HTML/CSS/JS GitHub Pages 项目的数据库连接信息? - How do I hide database connection information for a vanilla HTML/CSS/JS GitHub Pages project? 如何将 CSS 和 js 文件捆绑到一个 HTML 文件中? - How do I bundle CSS and js files into a single HTML file? 如何将内部JavaScript文件链接到GitHub中的HTML文件 - How do I link an internal JavaScript file to my HTML file in GitHub 网络托管:GitHub页面不显示HTML,CSS和JS文件 - Web Hosting: GitHub Pages Not Displaying HTML, CSS, and JS Files 无法将我的JS文件链接到我的HTML页面 - Unable to link my JS files to my HTML pages 如何将我手动添加到项目(JS 和 CSS)的资产文件自动链接到模板文件 - How to automatically link asset files that I add manually to my project (JS and CSS) to a template file drupal主题:如何在我的主题的.info文件中包含几个css文件/ js文件? - drupal themes: how do I include several css files / js files on my theme's .info file? 为什么我的 CSS/JS 不能在 Github 页面上运行? - Why is my CSS/JS not working on Github pages? 如何将我的 HTML 按钮链接到 JS onclick - How do I link my HTML button to a JS onclick
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM