无法为GitHub页面加载CSS [英] CSS not loading for GitHub pages

查看:75
本文介绍了无法为GitHub页面加载CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发布了GitHub页面的网站:

I have a site published with GitHub pages:

https://safelyswift.github.io/Swizzle/

我要使用 docs / css / style.css 在我的 index.html 文件中。我试过使用完整的url,GitHub的原始url和缩短的url,但它们都不起作用。

I want to use docs/css/style.css in my index.html file. I have tried using the full url, GitHub raw url, and shortened url but none of them work.

ie:我已经尝试过以下方法:

ie: I have tried many variations on this line:

<link rel="stylesheet" href="https://github.com/SafelySwift/Swizzle/blob/master/docs/css/style.css">



<link rel="stylesheet" href="/Swizzle/docs/css/style.css">



<link rel="stylesheet" href="https://raw.githubusercontent.com/SafelySwift/Swizzle/master/docs/css/style.css">

但无用。

出错:

Did not parse stylesheet at 'https://github.com/SafelySwift/Swizzle/blob/master/docs/css/style.css' because non CSS MIME types are not allowed in strict mode.

在Safari调试控制台中。

in Safari debug console.

推荐答案

您应该链接到 css / style.css ,这比 https://safelyswift.github.io/Swizzle/css/style.css ,因为GitHub页面的根目录为 / docs

You should link to css/style.css, which is short of https://safelyswift.github.io/Swizzle/css/style.css because the root directory of your GitHub Page is /docs.

原因 https://github.com/SafelySwift/Swizzle/blob/master/docs/css/style.css 不起作用是因为此链接实际上转到GitHub代码预览页面。这不是有效的CSS文件,而是具有许多GitHub函数(预览,提交日志,历史记录等)的HTML页面。但是 https://safelyswift.github.io/Swizzle/css/style.css 由GitHub Page提供,因此此链接仅包含有效的纯CSS文件。

The reason "https://github.com/SafelySwift/Swizzle/blob/master/docs/css/style.css" not work is because this link actually goes to the GitHub code preview page. It's not a valid CSS file but an HTML page with lots of GitHub functions(preview, commit log, history, etc.) But "https://safelyswift.github.io/Swizzle/css/style.css" is served by GitHub Page, so this link contains only pure CSS file which is valid.

查看这些文件之间的区别。只需使用浏览器浏览这些链接,然后右键单击您的页面即可查看源代码。您可以在那里看到浏览器的内容。

To see the difference between these files. Just navigate these link with your browser, and right-click your page to see the source code. You can see what your browser sees there.

这篇关于无法为GitHub页面加载CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆