16

I'm hosting a github page and want to link index.html to main.css, which is in a folder called "stylesheets" also in the root directory.

my file structure:

index.html
stylesheets
   - main.css

right now I have:

<link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />

in the <head>, but this doesn't work?

3 Answers 3

15

First, you should create gh-pages branch that special branch of GitHub.
You can find and create it in setting page of you project by the button Automatic page generator.
The branch will map to the doamin http://username.github.io/project/

So the path should be stylesheets/main.css not /stylesheets/main.css

Sign up to request clarification or add additional context in comments.

2 Comments

this is just a user site, not a project site
This answer is from 2014. GitHub Pages still supports the gh-pages branch, but these days it's not essential. Most likely just put their website in the /docs directory.
2

if it not project pages.. "mean" you are Creating a repo youruser.github.io (index of username.github.io) not atuo genereate gh-pages because its use template

its simply by doing:

  1. clone it
  2. create & move to branch gh-pages
  3. commit & push it

    /style -> you are on root directory
    style/ -> you are on currrent directory
    ./style --> more safe to navigate current directory

wait 5 minutes ... and cheers!

1 Comment

+1 for the "wait 5 minutes". The changes are not reflected immediately in the site youruser.github.io/yourproject
2

Try removing the front '/' from /stylesheet, so that it loads up relative to the current route: stylesheet/...

1 Comment

This was actually the first answer, and it's correct. A little short on details, but correct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.