ASP.NET CSS File on the Home Page

In my application, I have the following problem. I created the main page and some content pages, some of which are in subfolders. On the main page, I added a link to the .css file

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

But pages in subfolders cannot use this .css file. How can i fix this? I want to have one .css file for all pages (:

Thanks!

+4
source share
5 answers
 <link href="~/default.css" rel="stylesheet" type="text/css" /> 
+10
source

This problem can be solved by adding the following code on the main page.

 <style type="text/css" runat="server"> @import '<%= ResolveUrl("~/default.css")%>'; </style> 

But the VS developer cannot handle this, and you cannot view your styles in it.

+6
source

If you use a website under a website, change the link to the main page of the CSS subfolder

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

change below

 <link href="../Styles/Site.css" rel="stylesheet" type="text/css" /> 
+3
source

Css should not relate to the main page, but rather should relate to the location of the page instance using the main page. In most cases, this will be the same thing, but I always try to use either the full path or the relative path of the site

Fully qualified way

 <link href="http://some.site.com/mysite/styles/default.css" rel="stylesheet" type="text/css" /> 

or relative path (note that this may not work if you have a version that can host only one site, but many applications such as WinXP)

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

Win relative xp path

 <link href="/path/to/application/default.css" rel="stylesheet" type="text/css" /> 
+2
source

How did you define the stylesheet: the stylesheet is in the same folder as the page that uses it.

If you want to have one stylesheet for all pages that you have to put in one place (I prefer the /assets/css folder in the root of the application) and determine the path using this folder:

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

Another way to archive this is to use Themes , in which case styles will be added automatically.

+1
source

Source: https://habr.com/ru/post/1307928/


All Articles