CSS not being applied in pages :/ #22495
-
Hello eveyone, I am new to github. I’ve been following tutoials etc on how to set up pages. Now, i’m trying to move my codepen HTML and CSS over here. HTML is working, but CSS is not being applied. I’m obviously doing something wrong. But I can’t figure it out. https://github.com/noethix/trial Thank you in advance fo any pointers. Cecile |
Beta Was this translation helpful? Give feedback.
Replies: 26 comments 18 replies
-
Hi @noethix, Looking at your page, it appears the issue is the “/” at the beginning of your stylesheet’s source. Change “/css/main.css” to “css/main.css” (on line 5 of index.html) and it should fix the issue you’re having. For future reference, if the html file is in the same directory as another folder or file, you don’t need to include a slash at the beginning of the src or href attributes. Also, if you need to access files up one, two, or however many directories, you can use two periods as a substitute. (example below) say our folders are… root --> resources --> stylesheet.css root --> lessons --> lesson-1 --> exercise-1 --> index.html For our html file to access the stylesheet we could provide the following.
Basically two “…” moves up a directory and since index.html was three directories down, we moved up three times until we were in the root thus able to access the resources folder. You can also reference the current directory with “./”. If any questions, let us know. |
Beta Was this translation helpful? Give feedback.
-
Thank you @sethclydesdale for your detailed answer and the tips ! But it didn’t work either… |
Beta Was this translation helpful? Give feedback.
-
CSS appears to be working when I look at https://noethix.github.io/trial. Do you see it as working now? Or can you describe what is not working for you? |
Beta Was this translation helpful? Give feedback.
-
Thank you, that helped me so much; not only for CSS but also for IMAGE directories (I used to work with underline before its names, like: “_css or _image”). So, I had to took them off and changed on HTML and CSS as well so it could work. |
Beta Was this translation helpful? Give feedback.
-
Hello, I am facing the same issue. Did you happen to find a fix for it?
|
Beta Was this translation helpful? Give feedback.
-
Hi, I tried few things which worked for me. I assume those are not major reasons; but still you can try
<meta charset=“UTF-8”> It worked then; I reshuffled the order to check if that is the reason; it is working since then for no absolute reason for shuffling the order. And I am assuming each time you commit the change; in settings under GitHub Pages Section revisit the master brance in source option and then publish. |
Beta Was this translation helpful? Give feedback.
-
Hi, I tried few things which worked for me. I assume those are not major reasons; but still you can try
<meta charset=“UTF-8”> It worked then; I reshuffled the order to check if that is the reason; it is working since then for no absolute reason for shuffling the order. And I am assuming each time you commit the change; in settings under GitHub Pages Section revisit the master brance in source option and then publish. |
Beta Was this translation helpful? Give feedback.
-
Can you help me with mine? |
Beta Was this translation helpful? Give feedback.
-
Hello @noethix, Thanks for bringing up this topic, as this is a very common issue we see! First of all, it does appear that after making the change suggested by @SethClydesdale your CSS did start working, and https://noethix.github.io/trial/ looks great! Sometimes it can take a minute for updates to show up, or an old version is cached by your browser, and I suspect that’s what happened here. It also looks like @MangbawiTawmbing’s issue has been resolved as well, as I see that https://mangbawitawmbing.github.io/ludo/dicee.html is correctly displaying its CSS. For all those coming to this topic later with a similar issue, below are some common situations where we see CSS not working properly, and how to fix it. Check for these common issues:Incorrect URL to the stylesheetSometimes people accidentally use a stylesheet URL/directory path for their local computer, e.g. Solution: You can learn more about relative paths and how to create them here. Incorrect path to the stylesheetSometimes people reference the stylesheet at the wrong place, e.g.
Solution: Incorrect capitalizationPeople can also accidentally have capitalization that doesn’t match the filename. For example, the stylesheet is referenced like this: However, the file is named Solution: Better Solution: Missing file or directorySometimes we find that the stylesheet or even entire css directory was never uploaded or pushed to the repository. This often happens when using the web interface to upload files. Solution: CSS stops working after adding custom domainWe often have people write in to tell us that their CSS was working fine until they added a custom domain to their repository. One way to prevent many of these types of issues is to use relative paths, but some site builders do use the full URL as a base path, so you may need to change a setting or two. Solution: For Jekyll sites, edit For React sites, edit For example, if your
If your
Additional ResourcesIf you are here looking for a solution to your CSS issue, I hope we’ve been able to help with the information above! Here are some additional resources that may be helpful: Explanation of absolute vs. relative paths: What is a URL?With Hypertext and HTTP, URL is one of the key concepts of the Web. It is the mechanism used by browsers to retrieve any published resource on the web. Introduction to using cascading style sheets: CSS: Cascading Style SheetsCascading Style Sheets (CSS) is a stylesheet language used to describe the presentation of a document written in HTML Instructions on deploying a React app to GitHub Pages: Create React App · Set up a modern web app by running one command.`npm run build` creates a `build` directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served `index.html`, and requests to static paths like `/static/js/main..js` are served with the... |
Beta Was this translation helpful? Give feedback.
-
Hello :slight_smile: , i also encountered same problem . i tried diff ways and methods but still the css was not working in Github Pages [SOLUTION] : first make your complete project locally on your PC and after finishing it. create a repository and click on the option uploading an existing file : and then just drag and drop your whole project. if u want to edit something, then directly edit the code on github website. don’t use command line for github pages. my repo : https://github.com/HarshitKumarOjha/HarshitKumarOjha.github.io |
Beta Was this translation helpful? Give feedback.
-
your solution actually worked. thank you so much |
Beta Was this translation helpful? Give feedback.
-
This did work and it is such a strange workaround. Adding image path in the css with ./img/1.jpg didn’t work., neither did img/1.jpg. Not the greatest behavior. There definitely is a bug here. You can see the oddities in https://gradientus.github.io/tea/ |
Beta Was this translation helpful? Give feedback.
-
Thank you it really helped a lot |
Beta Was this translation helpful? Give feedback.
-
my bootstrap code is not working when i uploaded my file on github GitHubRohit-1604/fitnessContribute to Rohit-1604/fitness development by creating an account on GitHub. |
Beta Was this translation helpful? Give feedback.
-
Hi @Rohit-1604! Jekyll is ignoring the Since it doesn’t look like you’re using Jekyll, one way to solve this would be to create an empty file named |
Beta Was this translation helpful? Give feedback.
-
Now I have created the empty file named .nojekyll in the repository root. but even after that bootstrap is not applied on the page. root repository - https://github.com/Rohit-1604/fitness.git |
Beta Was this translation helpful? Give feedback.
-
Copy follwing code to your site
Or create a new file |
Beta Was this translation helpful? Give feedback.
-
I had this problem and I couldn’t find solution anywhere. All the folders where I placed css at were named with names starting with underscore( _ ), so I take off all underscores then it works. For example, the “_css” folder was renamed to “css”. I don’t know why it happens. Does GitHub Pages pages treat folders whose name starts with underscore as they are hidden, the same way linux hide folders whose name starts with a period( . )? Maybe |
Beta Was this translation helpful? Give feedback.
-
I am facing the same problem. HTML is working, but CSS is not being applied.I can’t figure it out kindly help. link to website is: https://vaishnavipandey.github.io/Personal-CV/ |
Beta Was this translation helpful? Give feedback.
-
My css file doesn't work properly and the above debugging doesnt help... |
Beta Was this translation helpful? Give feedback.
-
I am facing the same problem. HTML is working, but CSS is not being applied.I can’t figure it out kindly help. link to website is: https://shaikaleem254.github.io/portfolio/ |
Beta Was this translation helpful? Give feedback.
-
Hi! I have the same problem, some bg-images don't show on the page after deployment. I tried all advice from this thread, removed all slashes from paths, add type="text/css" and even moved index.css to root, but it doesn't work for me. Maybe I'm blind :( My repo - https://github.com/Lanarish/frontend66_group1 |
Beta Was this translation helpful? Give feedback.
-
Hi! I had the same problem. I'm coding using the Angular framework and had to build and deploy the website, so making changes in CSS messed with the build causing the website to remain the same no matter what I attempted to do. So, anyone else having the same issue and using Angular, please rebuild and redeploy your website. |
Beta Was this translation helpful? Give feedback.
-
I just had a similar problem, the names of my CSS and JS files started with _. Normally it works without any problems, but such a problem occurred on Github.io. As a solution, I fixed it by deleting the _ character at the beginning of the file names. Also, do not forget to change the href link after changing the file name. |
Beta Was this translation helpful? Give feedback.
-
Hi .. @SethClydesdale could you please help me I deployed my portfolio and the CSS is not applied. this is my link. https://sushree-0312.github.io/Personal-Portfolio/ |
Beta Was this translation helpful? Give feedback.
-
why my css is not applied. |
Beta Was this translation helpful? Give feedback.
Hello @noethix,
Thanks for bringing up this topic, as this is a very common issue we see! First of all, it does appear that after making the change suggested by @SethClydesdale your CSS did start working, and https://noethix.github.io/trial/ looks great! Sometimes it can take a minute for updates to show up, or an old version is cached by your browser, and I suspect that’s what happened here.
It also looks like @MangbawiTawmbing’s issue has been resolved as well, as I see that https://mangbawitawmbing.github.io/ludo/dicee.html is correctly displaying its CSS.
For all those coming to this topic later with a similar issue, below are some common situations where we see CSS not working proper…