简体   繁体   English

CSS仅在Visual Studio Designer中工作

[英]CSS only working in visual studio designer

I'm working on a Web Application in Visual Studio 2008. For some reason the CSS only works properly inside visual studio. 我正在Visual Studio 2008中处理Web应用程序。出于某些原因,CSS仅在Visual Studio中正常工作。 I can see the CSS inside the design view of the page. 我可以在页面的设计视图中看到CSS。 When I view the page on localhost the CSS is not being applied. 当我在localhost上查看页面时,未应用CSS。 This is just a very simple sample that I am working with. 这只是我正在使用的一个非常简单的示例。 Only 2 pages, a master page, and a default page. 只有2页,一个母版页和一个默认页。

Here is the master page. 这是母版页。

<head runat="server">
<title>Foobar My Title</title>      
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link id="stylemain" href="Content/Style/main.css" rel="stylesheet" type="text/css"/> 
</head>
<body>

<form id="form1" runat="server">
<table border="1">
    <tr>          
    <td><a href="Default.aspx" class="topContent">Foobar</a></td>
    </tr>
    <tr>
    </tr>
    <tr>
    <td>test</td>        
    </tr>
</table>  
</form>
</body>
</html>

Here is my CSS 这是我的CSS

.topContent {
text-align: right;
background-color: #600;
color: White;
font-size: x-large;
text-decoration: none;
font-weight: bold;
padding: 10px;
height: 50px;

} }

Your CSS is probably at the wrong relative path. 您的CSS可能是错误的相对路径。 To fix, change your link to be app relative style, like this: 要解决此问题,请将您的链接更改为应用程序相对样式,如下所示:

<link id="stylemain" href="~/Content/Style/main.css" rel="stylesheet" type="text/css"/> 

The master page will resolve this correctly, no need for a runat="server" in this case. 母版页将正确解决此问题,在这种情况下,无需runat="server"

问题出在IIS7上,我没有检查静态内容

Did you change the CSS file recently? 您最近是否更改了CSS文件? Maybe an old version of the CSS file is in the browser cache. 也许浏览器缓存中有旧版本的CSS文件。 Clear your browser cache and see if that fixes the problem. 清除浏览器缓存,看看是否可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM