问题
Iv'e got a content page with a link to a style sheet which I want to be specific for that page , i.e. I want the design to be specific for that page when it loads and takes its place in the contentplaceholder on the main page.
IN MY CONTENT PAGE :
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="~/Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />
</asp:Content>
IN MY MAIN PAGE :
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
MY STYLE SHEET ~/Styles/StyleSheet1.css just for example I'll give this id to some table in my content page.
#defualt_tbl
{
background-color:Gray;
}
<table id="defualt_tbl">
The table does not become gray , when I click viewsource in the master page the link is present in the head section.
<link href="~/Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />
回答1:
You can only use the ~
root specifier in server controls, the browser doesn't understand that URL, and doesn't know where your application root is either even if it would.
Put runat="server"
in the link
tag, or use an URL that is relative to the site root:
<link href="/Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />
回答2:
I'm not sure you can use the tilda ~ for the path in the link. I think the tilda(~) is a .net shortcut, and since your just rendering html the browser won;t know where to look.
回答3:
found it !
but i belive your answers work as well .
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href='<%= ResolveClientUrl("~/Styles/StyleSheet1.css") %>' rel="stylesheet" type="text/css" />
</asp:Content>
来源:https://stackoverflow.com/questions/7431694/css-style-sheet-from-content-page