简体   繁体   English

CSS无法在Visual Studio 2012设计器中应用?

[英]CSS not being applied in Visual Studio 2012 designer?

I have some css, which when inside my CSS file isn't applied to my designer in Visual Studio, but is applied to the page when I publish it. 我有一些CSS,在CSS文件中时,这些CSS不会应用于Visual Studio中的设计器,而在发布时会应用于页面。 This issue is slowing down site development massively as I'm trying to pick up CSS as I go... 当我尝试使用CSS时,这个问题正在极大地减慢网站开发的速度...

Here's a sample bit of CSS: 这是CSS示例:

.header {
    background-color: #ccc;
    border-bottom: 1px solid #666;
    color: #222;
    display: block;
    font-size: 20px;
    font-weight: bold;
    padding: 100px 100px 100px 100px;
    text-align: center;
    text-decoration: none;
        text-shadow: 0px 1px 0px #fff;
    background-image: -webkit-gradient(linear, left top, left bottom, 
                                       from(#ccc), to(#999));
}

Me applying the CSS on the page: 我在页面上应用CSS:

<header>
    <asp:Label ID="lblQuestion" runat="server" Font-Bold="True" Font-Size="16pt" Text="Your question goes here..." CssClass="header"></asp:Label>
</header>

Me adding the CSS to the page: 我将CSS添加到页面:

<link rel="stylesheet" type="text/css" href="mycss.css" media="only screen and (max-width: 480px)" />

I'm pretty new to CSS, so I'm hoping someone can tell me what I'm doing that is stopping Visual Studio rendering the CSS properly in the designer... 我对CSS很陌生,所以希望有人能告诉我我正在做什么,这是为了阻止Visual Studio在设计器中正确渲染CSS ...

Also, if I put my CSS tags directly in the page then it works, but I'd much rather keep my CSS out in it's own file, where it can be reused. 另外,如果我将CSS标记直接放在页面中,那么它可以工作,但是我宁愿将CSS保留在它自己的文件中,以便在其中重复使用。

Example style working: 样式工作示例:

<style>
    .header {
        background-color: #ccc;
        border-bottom: 1px solid #666;
        color: #222;
        display: block;
        font-size: 20px;
        font-weight: bold;
        padding: 100px 100px 100px 100px;
        text-align: center;
        text-decoration: none;
        text-shadow: 0px 1px 0px #fff;
        background-image: -webkit-gradient(linear, left top, left bottom, from(#ccc), to(#999));
    }
</style>

Thanks 谢谢

I suggest taking a look at Jeff Widmer's blog post, Why does Visual Studio not resolve my CSS class names? 我建议看看Jeff Widmer的博客文章, 为什么Visual Studio无法解析我的CSS类名?

Basically, site relative path's aren't supported by Visual Studio. 基本上,Visual Studio不支持站点相对路径。 It is the same reason why intellisense doesn't work for javascript. 这是为什么intellisense无法在javascript中工作的相同原因。

He offers a fix for this issue: 他提供了此问题的解决方法:

<link href="/content/default.css" rel="stylesheet" type="text/css" />
    <% if (false) {%>
        <link href="../../content/default.css" rel="stylesheet" type="text/css" />
    <% } %>

UPDATE: 更新:

The problem here was the media element in the link tag for the css. 这里的问题是CSS的链接标记中的media元素。 It doesn't appear that VS knows what that tag is and thus doesn't try to resolve the url. 似乎VS并不知道该标签是什么,因此不会尝试解析该url。

In this case, the css file is in the same folder as the page, so it would work. 在这种情况下,css文件与页面位于同一文件夹中,因此可以正常工作。 But, if the css file is moved into another folder, then it would stop working and the fix above would solve the issue. 但是,如果将css文件移动到另一个文件夹中,则它将停止工作,并且上面的修复程序将解决该问题。

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

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