I'm currently developing an ASP.NET Web Application and facing issues with applying CSS styles. In my project, I have a Master Page and a Content Page. Strangely, the CSS style is successfully applied to the Master page but not to the Content page. While in design view, the style appears on the Content page, it doesn't reflect when the page is loaded in a browser. I've experimented with internal and external style sheets, where inline styling works but I prefer to avoid it. Below is a snippet of the code that I have used:
Master Page:
<head runat="server">
<title></title>
<link rel="stylesheet" type="text/css" href="~/Styles/MasterStyleSheet.css" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
Content Page:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link rel="stylesheet" type="text/css" href="~/Styles/LoginStyleSheet.css" />
<!-- <link href='<%= ResolveUrl("~/Styles/LoginStyleSheet.css") %>' rel="stylesheet" type="text/css" /> I tried this as well-->
</asp:Content>
To demonstrate correct syntax, here is a sample CSS file:
LoginStyleSheet.css
#usrLabel {
color:Blue;
background-color:Aqua;
}
#Label4 {
background-color:Black;
}
Any assistance on this matter would be highly appreciated.
Update #1
Here is the HTML output for the header:
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="../Styles/MasterStyleSheet.css" />
<!-- <link href="<%= ResolveUrl("~/Styles/MasterStyleSheet.css") %>" rel="stylesheet" type="text/css" /> -->
<!-- <link rel="stylesheet" type="text/css" href="../Styles/LoginStyleSheet.css" /> -->
<!-- <link href='/Styles/LoginStyleSheet.css' rel="stylesheet" type="text/css" /> -->
<!-- <link rel="stylesheet" type="text/css" href="~/Styles/LoginStyleSheet.css" /> -->
<!-- <link rel="stylesheet" type="text/css" href="../Styles/LoginStyleSheet.css" /> -->
<!-- <link rel="stylesheet" type="text/css" href="/Styles/LoginStyleSheet.css" /> -->
</head>
Several <link>
elements are commented out which represent different methods I have tried.
Update #2
I want to express my gratitude for all the responses received so far, focusing on the issue of why the external CSS file isn't working. Even with an internal CSS style sheet, the problem persists. Only inline CSS styling seems to function correctly. Perhaps identifying the root cause behind the failure of internal CSS styling could potentially resolve the issue with external CSS style sheets as well.