在Aspx页面和母版页中引用CSS工作表 [英] Referencing CSS Sheet in Aspx page with Master Page

查看:91
本文介绍了在Aspx页面和母版页中引用CSS工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题在标题中很好地陈述了。通常,我会使用< link ... /> 来引用我的CSS工作表,但是由于我使用的是母版页,因此我无法访问 Head 标签,因此如何在ASPX页面上引用特定的CSS表。我尝试使用<%@导入命名空间= Style.css ,但是没有运气。谢谢您的帮助。

Question is pretty well stated in the title. Normally I would use <link... /> to reference my CSS Sheet but since I'm using a master page I don't have access to the Head Tag so how do I reference a specific CSS sheet on my ASPX page. I tried using <%@ Import Namespace="Style.css" but no luck. Thanks for the help.

推荐答案

只需添加一个CSS ContentPlaceHolder,默认值即可。

Just add a CSS ContentPlaceHolder with a default value in it.

基本上,将包含您指定为默认值的CSS文件,除非您用子页面中的标记覆盖该占位符。

Basically, the CSS file you specify as default will be included unless you override that placeholder with an tag from a child page.

<head>
    <asp:ContentPlaceHolder ID="Stylesheets" runat="server">
        <link rel="stylesheet" href="/css/master.css" type="text/css" />
    </asp:ContentPlaceHolder>
</head>

然后从使用该母版页的任何页面中,您都可以使用其他样式表简单地覆盖它。

Then from any pages using that Master Page, you can simply override that with a different stylesheet.

关于(示例)AboutUs.aspx

<asp:Content ID="Content1" ContentPlaceHolderID="Stylesheets" runat="server">
    <link rel="stylesheet" href="/css/Style.css" type="text/css" />
</asp:Content>

这篇关于在Aspx页面和母版页中引用CSS工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆