我有一个母版页,我想将此母版页的一部分绑定到* .css文件但没有成功。这是我的母版页代码:
<head runat="server" >
<title></title>
<link href="~/Styles/Test.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server" >
</asp:ContentPlaceHolder>
</head>
<body>
<form runat=server>
<body>
<table width=100% border=1>
<tr width=100%>
<td ></td>
<div class=mainbody>
<td width=80% align=center>
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</td>
</div>
<td ></td>
</tr>
</table>
</body>
</form>
</body>
在我的css文件中我有:
body
{
}
mainbody
{
background-color:#a0ccff
}
请告诉我,为什么它不起作用?
答案 0 :(得分:7)
类选择器应以点
开头.mainbody
{
background-color:#a0ccff
}
答案 1 :(得分:1)
看,你不能把一个td放在DIV元素中......从
改变你的代码... <head runat="server" >
<title></title>
<link href="~/Styles/Test.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server" >
</asp:ContentPlaceHolder>
</head>
<body>
<form runat=server>
<body>
<table width=100% border=1>
<tr width=100%>
<td ></td>
<div class=mainbody>
<td width=80% align=center>
<asp:ContentPlaceHolder ID="MainContent" runat="server"></asp:ContentPlaceHolder>
</td>
</div>
<td ></td>
</tr>
</table>
</body>
</form>
</body>
...
到
<head runat="server" > <title></title>
<link href="~/Styles/Test.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="HeadContent" runat="server" >
</asp:ContentPlaceHolder>
</head>
<body>
<form runat=server>
<table width=100% border=1>
<tr width=100%>
<td ></td>
<td width=80% align=center>
<div class=mainbody>
<asp:ContentPlaceHolder ID="MainContent" runat="server"> </asp:ContentPlaceHolder>
</div>
</td>
<td ></td>
</tr>
</table>
</form> </body>
然后它将按您的意愿工作(我建议您复制我的代码并将其粘贴到您的SIte.Master文件中)
答案 2 :(得分:0)
尝试:
<link href="/Styles/Test.css" ...>
而不是:
<link href="~/Styles/Test.css" ...>