In this article I am going to show you how to properly load the CSS style sheets of the master page for your ASP project.
CSS files contain style rules that are applied to elements in a Web project. Usually, you can define how elements are displayed and where they are positioned on the page with CSS. If your ASP application is not looking like it is suppose to be, it must be that the CSS files are not loading properly.
1. Open your ASP project with Visual Studio:
2. Specify your stylesheet links with runat=server and prefix them with the virtual web root path (~).
It has to look something like this:
<link href= "~/css/styles.css" rel="stylesheet" runat="server" type="text/css" />
3. The image URL’s in the CSS file must be updated as well. If you are going to put it in the same css folder, it has to be changed to a path traversal:
4. It is also a good practice to put the image folder inside the css folder. That way the path won’t have to be changed to a traversal one:
5. Finally, please keep in mind that all head elements (JS files, Fonts, etc.) need to have the runat=”Server” element tag.
This concludes Fix CSS not loading in ASP