How to link my CSS to my HTML in a github hosted site

Viewed 10025

My problem is that my website that I'm attempting to host with Github pages will not read the CSS that I have linked to it.

My HTML looks like this:

<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="https://github.com/legoman8304/legoman8304.github.io/blob/master/style.css">
<html>
    <body>
        <h1>Hello World</h1>
        <p>I'm under construction!</p>
        <h6>Copyright MIT Licence 2018</h6>
    </body>
</html>

My CSS looks like this:

body {
  background-color: lightblue;
}

h6 {
  color: navy;
  margin-left: 20px;
}

Link repository: legoman8304.github.io

I'm guessing I linked the CSS wrong because when I using inspect element on the site itself it does show style.css but when opened it's empty. Any help?

2 Answers

You need to link your HTML to the github page rendered style.css and not the file itself in the repo.

Change this:

<link rel="stylesheet" type="text/css" href="https://github.com/legoman8304/legoman8304.github.io/blob/master/style.css">

To this:

<link rel="stylesheet" type="text/css" href="https://legoman8304.github.io/style.css">

And move that stylesheet reference inside your <head> tag.

You can use some way:

  • Recommend: <link type="text/css" rel="stylesheet" href="style.css" />

  • Use from raw your css with href: https://raw.githubusercontent.com/legoman8304/legoman8304.github.io/master/style.css

Related