开发者

How to switch themes in web browser

I want to change the theme in an asp.net website. 开发者_如何学Cbut i have to give the normal effect of switching themes?


You can do this by switching style sheets - you can do this using javascript - there is a script around that uses cookies to do this so the theme is persistent - other wise you can probably do it in asp using sessions.


My best advice is to store the theme name in user's client variable.

Here is Coldfusion style

<cfset client.myTheme = "forest">
<link rel="stylesheet" href="theme/<cfoutput>#client.myTheme#</cfoutput>.css" media="screen" type="text/css"/>


Another way to do it would be to switch the class on a parent html element, such as <body>. This has the advantage of not requiring an extra stylesheet to download.

This does require you to have all of your different styles for the different themes loaded from the start, but in most cases, there are relatively few style rule changes for different themes and the majority of the CSS payload is taken up by reset styles and other general styling that apply to all themes (there are of course exceptions to this, but in the general case it tends to be true). Since the load-time cost of including an additional CSS resource is very high, and the payload increase (especially if serving compressed resources) is low, you don't incur any performance penalty by including the extra themes from the beginning, and in fact are likely to have a performance gain versus putting the theme styles in a separate file. Additionally, themes will switch much faster because there are no extra resources to load.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜