CSS not working on Localhost - css

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!

I would recommend referencing the CSS files relatively. So if you have the following folder structure.
myProj
- css
- bootstrap
- bootstrap.min.css
- index.html (or php)
Then you would reference the bootstrap file like so
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.min.css" />
Guessing at your folder structure from your example I would then assume that all you need is
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="main.css" />
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.
<link rel="stylesheet" type="text/css" href="http://localhost:8080/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="http://localhost:8080/main.css" />
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!

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 new style.css and my wamp server kept referencing the first style.css file I made.
So I renamed the second CSS file to main_style.css and everything worked perfectly.

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.

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:
Open DevTools
Right-click on reload button(top-left)
Click on 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.

Related

Bootstrap working via link, but not when downloaded

I am trying to do some website by using Bootstrap and Spring Boot.
When I put web location of bootstrap.min.css in href, it is working perfectly.
Code:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
But when I download the same library and put it in a folder, Bootstrap is not recognized at my website.
Code:
<link rel="stylesheet" href="/static/bootstrap-4.5.2-dist/css/bootstrap.min.css">
Can someone explain me how to fix this problem?
I manage to figure this out. Despite the fact that location of file is in static, Spring boot recognizes automatically that it is in static, so it is enough to write href="/bootstrap-4.5.2-dist/css/bootstrap.min.css".

Fonts and Font Awesome icons not loading over SSL

I'm trying to get my website to load correctly over SSL, and every time I view the page, the icons and font aren't loading.
Here's what I'm using for my CSS and font awesome.
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.min.css" rel="stylesheet">
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600' rel='stylesheet' type='text/css'>
Here's a link to the website in case you want to check the full code
Try remove http: from href:
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
There is a great article about protocol-relative here: paulirish.com/2010/the-protocol-relative-url/
I had the same SSL/TLS error/issue over the chrome. It worked OK on the firefox. I had to switch the sources.
There is issue with MaxCDN you need to use KeyCDN.
Switch from:
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
to:
<link href="https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css" rel="stylesheet"/>
Try using
//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css
and maybe its a simple issue of using "http" instead "https" because the google apis use https for secure link transfer. Replace http with https
In my case change http source to https while using #import statement in css file works fine.
#import url(https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css);
[class*="fontawesome-"]:before {font-family: 'fontawesome', sans-serif;}
Try downloading the font-awesome zip (css & assets) and serve them from your own server/directory - instead of using the CDN links.
Then just refer to the font-awesome css file in your own directory using https://
This worked for me.
I assume your webbrowser blocked the HTTP resources from being loaded from a Server that is configured for HTTPS, which is referred to as "Mixed Content", and is flagged as a security risk.
A secure site should never load resources via a non-secure mechanism.
Perhaps your webbrowser auto-updated to a newer version that does not allow Mixed Content to the loaded.
What is Mixed Content? - Google Developers
I had this same problem - after lots of attempts using the CDN links, with and without https://.., I decided to download the font-awesome zip file and serve them instead from my own server.
Put all the css and assets on your own server, instead of loading them from the CDN link with https://..
Then, just refer to font-awesome.css file using https://..
Eg:
<link rel="stylesheet" href="https://yourdomain-name.com/assets/font-awesome-4.7.0/css/font-awesome.min.css">
This fixed it for me, after going round in circles.

css file mime type when using google docs as static site hosting

I tried to use google docs as static site hosting as described here: https://support.google.com/drive/answer/2881970?hl=en. But browser fails to apply css files. I see warning in chrome developer console : Resource interpreted as Stylesheet but transferred with MIME type text/plain : my_css_filename.css . I guess because of this browser fails to apply css.
The problem was I created text file, and when renamed it to css extension (in drive web interface). When I created css file on my computer with notepad and uploaded to google, everything began to work.
I had similar issue one month ago.
Solution
I think you have the following:
<link rel="stylesheet" type="text/css" href="my_css_filename.css">
You only need to had a /
<link rel="stylesheet" type="text/css" href="/my_css_filename.css">

CSS not showing up with ERB

I've just hosted something on Heroku, and whenever I opened the app it worked just fine with the css being linked as such:
<link rel="stylesheet" href="/css/style.css"/>
The problem came when I added my custom domain, the css no longer worked. When I view source and click on the href, it get a response "Not Found". Nothing has changed, my css folder is still in my public folder in my apps directory.
Have you tried different paths for the href, like
href="../css/style.css"
or
href="css/style.css"

asp.net newbie question - css href path

When start debug mode of my asp.net website, it renders in my browser with the url
http://localhost:111/mywebsite/Default.aspx
The css file is referenced like this in the html
<link href="~/css/style.css" runat="server" rel="stylesheet" type="text/css" />
So naturally the site breaks because it looks for the CSS file in localhost:111/css/ instead of localhost:111/mywebsite/css/.
When I launch the website, it will actually be served from the url:
http://mywebsite.com
So is there a way to reference my stylesheet properly in both my dev and production area with a simple prefix like <?=$site_url ?> or something?
Additional info
In my solution explorer, I see that my project is marked with the path C:\...\mywebsite. Is that why the ~ assumes my project is always in a subdirectory? How do I tell Visual Studios that this project should always be served as something like http://localhost:111/Default.aspx?
This is what I see in the page source of both my localhost and production server:
<link href="~/css/style.css" rel="stylesheet" type="text/css"></link>. The css is active on production, but not my localhost.
I went to the solution explorer, then selected the item in the tree labelled C:\...\mywebsite, then I went to the Properties window at bottom right of VS, and changed the Virtual path to /. Now my dev website's root is the same as my prod website's root.
This will do the trick.
<link href="<%=ResolveUrl("~/css/style.css")%>" runat="server" rel="stylesheet" type="text/css" />
You already have, ~ resolves to the root of the website when the page is rendered.
Further reading: http://weblogs.asp.net/fmarguerie/archive/2004/05/05/avoiding-problems-with-relative-and-absolute-urls-in-asp-net.aspx (which works in chrome, FF and IE).
~ resolves on the server (which is why you need runat="server").
This code is run to generate the response from a HTTP request that has come to your dev server which is hosting the site from the location of the project on your disk.
~ doesn't assume that the site is in a subdirectory, the dev server will know the root of the website.
In production the site is being hosted by IIS from another location on the disk of the server machine.
Change it to:
<link href="/css/style.css"" rel="stylesheet" type="text/css" />
Remove runat="server" (if you don't need it).
Instead of href="~/css/style.css" use: href="/css/style.css"
href="/css/style.css" means that there is a folder named css in root of your website and a file named style.css inside it.
UPDATE:
As pointed out by comments, this solution only works if your app is running in root.

Resources