Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing a .css file in github repo as stylesheet in a .html file

Tags:

github

I've got a repository on github with a .css file in it. Is there any way to have github serve this file in a way that I can consume it in a web page?

In other words, I'd like to be able to reference this source file at github directly, from an HTML file on my local computer or a live domain. Something like:

<link rel="stylesheet"       type="text/css"       href="http://github.com/foouser/barproject/master/xenu-is-my-lover.css" /> 

I've tried including a<link> to the "raw" source file (http://raw.github.com...), but github serves its Content-Type as text/plain, and consequently, Chrome and FF are not adding its content as CSS styles to the page—the file's data is being discarded and a warning is shown in the debugger consoles of the browsers.

like image 885
user979672 Avatar asked Oct 15 '11 20:10

user979672


People also ask

How do I link a github style sheet to HTML?

You need to link your HTML to the github page rendered style. css and not the file itself in the repo. And move that stylesheet reference inside your <head> tag.

How do you reference a stylesheet in HTML?

The <link> tag defines the relationship between the current document and an external resource. The <link> tag is most often used to link to external style sheets or to add a favicon to your website. The <link> element is an empty element, it contains attributes only.


2 Answers

Important: rawgit.com is shutting down. Read more about other alternatives here - https://rawgit.com/


Found something really cool. You get the raw link as: http://raw.github.com/...

Simply fetch the files from rawgit.com (or cdn.rawgit.com) instead of raw.github.com and DONE!


UPDATE:

You can also use raw.githack.com if you want to serves raw files directly from Bitbucket or GitLab

like image 132
Kushagra Gour Avatar answered Sep 21 '22 01:09

Kushagra Gour


GitHub repos aren't web hosting, you should push that stuff up to a service specifically designed to serve files, like pages.github.com.

like image 44
Tekkub Avatar answered Sep 25 '22 01:09

Tekkub