ASP.NET主题样式呈现 [英] ASP.NET Theme stylesheet rendering

查看:145
本文介绍了ASP.NET主题样式呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在与主题页面呈现,样式表链接在给定的主题标签中的结束标记前右呈现。有谁知道的一种方式来改变这种状况?有没有办法,我能有这些标签放置的方式开场头标记之后吧?

When a page with theme is rendered, the stylesheets link tags in the given theme are rendered right before the closing head tag. Does anyone know of a way to change that? Is there a way that I could have those tags be placed right after the opening head tag?

我知道它可以通过只选择所有的链接标签和开放的头标记后立即将其放置下来使用jQuery,但有没有办法把它放在服务器端的?

I know it can be down with jquery by just selecting all the link tags and placing it right after the opening head tag, but is there a way to set it on the server end?

澄清
让我们说我在我的主题一个CSS文件(themed.css)。在这个CSS文件,我有一个div标签的单一样式定义与测试的ID:

Clarification Let us say I have a single css file (themed.css) in my theme. In that css file, I have a single style definition for a div tag with an id of test:

#test {background-color:red; color:white;}

让我们也说我有第二个CSS文件(standard.css),它是不是在我的主题,但它有div标签的另一个定义与测试的ID:

Let us also say I have a second css file (standard.css) that is NOT in my theme, but it has another definition of the div tag with an id of test:

#test {background-color:yellow;}

我有我的页面使用的主题,我有一个手写的链接标记使用standard.css。当执行页,对于standard.css链接标记是themed.css之前。当发生这种情况我div标签测试ID具有红色背景和白色的前景色。如果我想的themed.css申请,然后standard.css覆盖必要的属性(黄底白前景色),我希望themed.css然后​​standard.css。我不能这样做,因为ASP.NET会将主题的结束标记前面正确的文件。

I have my page to use the theme, and I have a handwritten link tag to use standard.css. When the page is executed, the link tag for standard.css is before themed.css. When that happens my div tag with id of test has a red background and white forecolor. If I want the themed.css to apply and then standard.css to overwrite the necessary properties (yellow background with white forecolor), I would want themed.css and THEN standard.css. I can't do that because ASP.NET places the theme files right before the closing head tag.

我不希望有知道我的主题的CSS文件都在我的头标记的第n个链接标记,然后手动改变每当我可以添加一个新的CSS文件我的主题之外的任何指标。

I don't want to have to know that my theme's css files are the nth link tag in my head tag and then manual change any index whenever i may add a new css file outside of my theme.

谢谢!

推荐答案

我没有在反射器一点点检查,并发现了一些你可能会感兴趣。框架调用 SetStyleSheet A PageTheme 派生对象的方法注入环节控制在标题中。这code片段展示了相关的逻辑:

I did a little checking in Reflector, and found something you may find interesting. The framework calls the SetStyleSheet method of a PageTheme-derived object to inject link controls in the header. This code snippet shows the relevant logic:

int num = 0;
foreach (string str in this.LinkedStyleSheets)
{
    HtmlLink child = new HtmlLink { Href = str };
    child.Attributes["type"] = "text/css";
    child.Attributes["rel"] = "stylesheet";
    if (this._styleSheetTheme)
        this.Page.Header.Controls.AddAt(num++, child);
    else
        this.Page.Header.Controls.Add(child);
}

翻译? StyleSheetThemes注入样式表在 开始标题标签和主题在最终注入样式表

Translation? StyleSheetThemes inject the style sheets at the beginning of the header tag, and Themes inject the style sheets at the end.

这是与主题和样式表主题之间的差异目的相一致;即,当在皮肤和控制设置之间的冲突,一个主题总是获胜。当然,使用在非主题的.css文件的样式!重要属性仍然可以覆盖一个主题风格,但CSS文件的head标签内的定位有利于战略性覆盖能力风格主题。

This is consistent with the intended difference between themes and stylesheet themes; that is, that a theme always wins when there is a conflict between the skin and the control settings. Sure, a style in a non-themed .CSS file using the !important attribute could still override a theme style, but the positioning of the CSS files within the head tag strategically facilitates override-ability stylesheet themes.

请注意,你可以有的两个的样式表的主题和常规主题。当然,留到样式表主题的东西,你设计要覆盖的,还来不应该重写主题的东西。

Note that you can have both a stylesheet theme and a regular theme. Naturally, leave to the stylesheet theme things you design to be override-able, and to the theme things that should not be overridden.

最后一个观察是,该方法是内部和非虚,这两个选项,这样干扰会采取一些功夫-MMA-疯狂的反射能力,而可能是不稳定性或可维护性的最佳利益。

One final observation is that the method is internal and non-virtual, so interfering with these two options would take some kung-fu-MMA-mad-reflection skills, and is probably not in the best interest of stability or maintainability.

这篇关于ASP.NET主题样式呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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