简体   繁体   中英

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

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?

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

Guys i had the same problem but i solved it's easy guys, change your code to

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

actually the problem is with time ,after commit u have to wait a bit to propagate the same to github

Also frequently check the page source whether its updated on ur browser actually while we edit offline it will not take time but its opposite in online world so wait for 10-20 sec and frequently check whether your site is updated by reloading page source or website it will work definitely

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