Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

strangely when i link my css with below pattern its work as it is more obvious

<link type="text/css" href="../../../../css/PdfTemplateStyle.css" rel="stylesheet" />

but why not below things not working my css on my pages

<link type="text/css" runat="server" href="/css/PdfTemplateStyle.css" rel="stylesheet" />

or

<link type="text/css" runat="server" href="~/css/PdfTemplateStyle.css" rel="stylesheet" />

above to not at all working my css on a page ..
Posted
Updated 11-Dec-14 18:52pm
v2

1 solution

1. LINK is a HTML tag and not an ASPX tag, and runat attribute is defined only in the case of ASPX tags.

2.You should use relative paths, and they are relatives to the wen application root folder from IIS (or to web application project folder in Visual Studio), and should be like in the example below:
HTML
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />

In this example the Styles is a folder created directly in the web application root and it contains the CSSS file named: Site.css.

3.If you have your CSS file inside multiple sub-folders with 4 levels you have to indicate the path like below (but changing the name of the folders and CSS file for your case):
HTML
<link href="~/Folder1/Folder2/Folder3/Folder4/MyFile.css" rel="stylesheet" type="text/css" />
 
Share this answer
 
v2
Comments
Torakami 12-Dec-14 2:55am    
i tried to use relative path , but the css doesnt work in that case it works only when i apply four time ../
Raul Iloc 12-Dec-14 7:17am    
Should work if you did like I indicated in my 3rd point. Maybe you put also the name of the Web application folder that must not be in the path!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900