0

我有一个母版页,我想将此母版页的一部分绑定到一个 *.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 
}

盘绕,请告诉我,为什么它不起作用?

4

3 回答 3

7

类选择器应以点开头

.mainbody
{
  background-color:#a0ccff 
}
于 2012-06-14T07:51:17.040 回答
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 文件中)

于 2012-06-18T09:30:52.570 回答
0

尝试:

<link href="/Styles/Test.css" ...>

代替 :

<link href="~/Styles/Test.css" ...>
于 2012-06-14T08:05:59.797 回答