简体   繁体   English

母版页CSS使用母版页覆盖Web窗体CSS

[英]Master Page CSS overwriting Web Form CSS using Master Page

Update 更新

I had the syntax incorrect ~/Styles/Default.css needed to be /Styles/Default.css 我的语法不正确〜/ Styles / Default.css必须是/Styles/Default.css

I have a CSS page linked to the master. 我有一个链接到母版的CSS页面。

Now I created my Default.aspx page that uses the Master Page 现在,我创建了使用母版页的Default.aspx页

In Default.aspx 在Default.aspx中

<asp:Content ID="ContentHead" ContentPlaceHolderID="head" runat="server">
    <link rel="stylesheet" runat="server" href="~/Styles/Default.css" type="text/css"/>
</asp:Content>

<asp:Content ID="ContentBanner" ContentPlaceHolderID="banner" runat="server">
    <div id="banner">
        <img src="/Images/Banners/banner.gif" />
    </div>
</asp:Content>

Default.css Default.css

#banner
{
    background-color:#FDFD82;
}

In VS I see the background color of that div correctly but when I load it in IE it doesn't show. 在VS中,我可以正确看到该div的背景颜色,但是当我在IE中加载它时,它不会显示。 If I code the style into the div section and not CSS it works. 如果我将样式编码到div部分而不是CSS中,那么它将起作用。

What I'm I missing here? 我在这里想念什么?

visual studio reloads the style sheet, but the browser doesnt, it caches it once and uses it unless you reload it. visual studio将重新加载样式表,但浏览器不会,它会缓存一次并使用它,除非您重新加载它。

so, either press Ctrl + R in your browser to refresh it and have it reload all the resources, or use a trick which will make the browser reload the style sheet every time: 因此,可以在浏览器中按Ctrl + R刷新它并让它重新加载所有资源,或者使用一种技巧来使浏览器每次重新加载样式表:

<link rel="stylesheet" runat="server" href="~/Styles/Default.css?<%=DateTime.Now %>" type="text/css"/>

have a look at the link, i appended a query string with the current time. 看一下链接,我在查询字符串后面加上了当前时间。 the time changes always, and it makes the browser think its a different sheet, and reload it every time. 时间总是在变化,这使浏览器认为它是不同的工作表,并每次都重新加载它。

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

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