简体   繁体   中英

CSS - Failed to load resource: the server responded with a status of 404 ()

I'm just trying to load my simple website online hosted by Github.io. However, after countless and frustrating efforts of troubleshooting and debugging the HTML & CSS script, my web still couldn't get the CSS file loaded as desired for some really mysterious and extremely annoying reason.

Don't get me wrong:

  1. I swear my CSS file is put in the absolute path rather than the relative path as I firstly put it, so I will smash myself if it's the cause of the error.
  2. After a while couldn't figure out, I looked over similar or related issues posted on stackoverflow as well, some suggest that the access permission is maybe the reason, but I followed them with the command inside my directory of CSS file

chmod -R 777

But I don't see it resolves as well cuz the command has no effect, and I didnt run it at the root level 该文件不在根目录下

  1. I inspected this web on both Chrome and Safari, and the style.css is blank as it couldn't be loaded!!! 在此处输入图片说明

Now, I keep hold on this to wait for any of your "magic" helps. I deeply appreciate the help, as I tried my best fixing it already, but didnt work. Here is the just HTML link tag line where the file is not loaded.

<head>
....

    <link rel="stylesheet" href="./_css/style.css">
</head>

If your _css directory is in the root, your CSS link should start with a slash:

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

But naming your directory _css may be a problem. Github Pages by default treats your site as a Jekyll website, which processes your files and does not publish files/directories having _ prefix.

I think you have 2 options:

  • If you don't know about Jekyll and you are not creating a Jekyll site, put a file in your root named .nojekyll to bypass Jekyll processing .
  • Rename your directory from _css to css and also modify your <link> tag.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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