简体   繁体   中英

How to link CSS file in gitHub to my html file on local PC?

I am learning HTML and have written a couple of HTML scripts. I also know how to use CSS to style HTML webpages. I have an issue with linking a css file in my github page to a HTML script in my local computer. I am still practising HTML, but I can view how the HTML looks on a webpage through the HTML Preview extension in VS Code.

Here is my HTML code:

<html>
    <head>
        <title>A Big Title</title>
        <link rel="stylesheet" type="text/css" href="https://raw.githubusercontent.com/sammigachuhi/millennial_blogs/main/blog_styles.css">
    </head>
    <body>
        <h1>Header One</h1>
        <p>
Blah blah blah
        </p>
     </body>
</html>

The link to my html inside the href attribute is not working. I tried following advice from here where they mention changing it to read something like "https://sammigachuhi.github.io/millennial_blogs/main/blog_styles.css" to no avail. However, when I try with an publicly accessible css file such as href="http://www.w3schools.com/html/styles.css" the html changes to match the contents of that css file.

Could it be something with gitHub? Here is the link to my raw CSS file.

Hello @MaximilianBallard I found it. One simply needs to host the css file at Github pages, not the usual github site. I did it as follows: Go to your gitHub repository which hosts the css file. Go to settings. Under the General menu, go to Pages. Under "Pages", which shows as Github Pages, under 'Build and Deployment select 'From branch', select the location, preferable under a Docs folder for ease. This link helped me: https://autogis-site.readthedocs.io/en/2021/lessons/L5/share-on-github.html

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