Asp.net webform中的CSS

时间:2013-09-24 04:39:07

标签: asp.net css

我在网络表单中添加了一个css。 css在html文件和visual studio的设计视图中工作得很好。但是当它在IIS中运行时,不会显示css。请帮帮我。

CSS

body{
background: #efefef;
}

.head
{
margin-top:0px;
min-height:40px;
min-width: 102%;
background-color:green;
color:blue;
text-align:center;
margin-left:-10px;
margin-right:0px;
padding-top:10px;

}
#content
{
margin-top:10px;
margin-bottom:10px;
margin-left:0px;
min-height:100%;

}
 #wrapper
  {
  width:83%;
  min-height:inherit;
  background-color:red;
  float:left;
  }
  #sidebar
  {
  width:15%;
  float:right;
  }
  #sidebar1
 {
  background-color:green;
  min-height:20%;
  margin-bottom:2px;
 }
  #sidebar2
  {
  min-height:40%;
  background-color:blue;
margin-bottom:2px;
  }
  #sidebar3
  {
   background-color:violet;
   min-height:40%;
  }

HTML

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"             Inherits="_Default" %>
<link type="text/css" rel="stylesheet" href="E:\Demo\main.css" />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">


     <html xmlns="http://www.w3.org/1999/xhtml">
     <head runat="server">
     <title></title>
    </head>
     <body>
         <form id="form1" runat="server">
             <div class="head">Thiagarajar College of Engineering</div>
         <div id="content">
           <div id="wrapper">
               srini
            </div>
            <div id="sidebar">
            <div id="sidebar1">ji</div>
            <div id="sidebar2">sr</div>
            <div id="sidebar3">ni</div>
            </div>
        </div>
          </form>
     </body>
  </html>

2 个答案:

答案 0 :(得分:1)

您的CSS文件位置错误。

1)通常,CSS文件应位于head标签内。 (虽然你可以把它放在身体标签内的任何地方,我不推荐它。)

2)此外,链接应该是相对路径而不是E:\Demo\main.css

<head runat="server">
  <title></title>
  <link href="/main.css" rel="stylesheet" type="text/css" />
</head>

答案 1 :(得分:0)

将此代码粘贴到<head></head>这样的内容中。

<head>
<link type="text/css" rel="stylesheet" href="E:\Demo\main.css" />
</head>

如果没有将您的css文件放入项目中,只需将其拖放到页面中即可。