I am building a site and had all of my CSS, HTML working wonderfully. I wanted to add in some PHP functionality so I have created a local development environment on my mac with Apache. I then moved all of my site folders to my new Sites folder that can be accessed by localhost. When loading my website and now none of my CSS styles are loading. I am using Twitter Bootstrap locally. This is what my css links look like in my html:
link rel="stylesheet" type="text/css" href="http://localhost/~tromph/YoointooSite/bootstrap.min.css">
link rel="stylesheet" type="text/css" href="http://localhost/~tromph/YoointooSite/main.css">
I’ve tried just about every other path that I can think of and nothing else seems to work.
I changed my folder structure and the file path to:
<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.2-dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/bootstrap-3.3.2-dist/css/main.css" />
This fixed my problem of not having the CSS render. Now the images linked in the CSS are not showing. Dev tools is telling me that I am getting an error 403 (forbidden) on each of my images. What should I do to change this permission?
I spent some time updating permissions. Everything is working now. Thanks for your help!
6
Answers
I would recommend referencing the CSS files relatively. So if you have the following folder structure.
Then you would reference the bootstrap file like so
Guessing at your folder structure from your example I would then assume that all you need is
If however your css files are not in your project, but instead are served externally, then you would need to reference them from wherever you are serving them. For example if serving them to port 8080, then you would need to reference them using that address instead.
Again, the above is only if you are serving them externally from the site that you are attempting to use them from. If they are inside of the project you are working on, then reference them relatively from the file attempting to use them.
The first thing I would look at is whether or not it’s a path issue with your styleheets. Use web inspector or dev tools in your browser and look for a 404 error in your CSS files. If there are any, dev tools will show the path it’s looking for and you can adjust the path to your style sheets accordingly.
Good luck!
Use Developer tools in google chrome or other browser and in the sources tab look for errors. Two common errors are your css files not being found (see relative path answer above) or maybe your file permissions don’t allow the Apache server to access the CSS files.
Thought I’d throw my input into the works.
I named one of my CSS files
style.css
than later went and deleted it and created a newstyle.css
and my wamp server kept referencing the firststyle.css
file I made.So I renamed the second CSS file to
main_style.css
and everything worked perfectly.I once faced the issue of CSS not being applied when I was working with PHP.
I fixed this issue by doing
Empty Cache and Hard Reload
(chrome).To do that:
Empty Cache and Hard Reload
After doing this, all my CSS styles were applied.
I also faced same problem but later found a solution to it. Just Press ‘Ctrl+F5’ when the css file doesn’t open on the browser window.