开发者

Themes Vs. Old School Stylesheets

I have been developing websites with ASP.NET for quite a while. When I first learned how Themes and Skins work in ASP.NET, I found that it's great and easy and all.

But later on, I started to find the App_Themes approach pretty annoying, and the CSS we put in it, are not flexible at all and in any way. Am I missing something?

  1. CSS files are automatically added to aspx pages using the theme:

    I used to find this helpful back when I first started web development. But later on, when I learned more and more about CSS, I started to find this really disturbing. Sometimes, there are some pages, where it's useless to add a certain CSS file.

    And the worst part, it always adds them in alphabetical order, thus you have no control which file is first. This is important specially if you have done some sort of a "reset" CSS file. Thus naming the files can't always be what u want them to be, since you want the reset CSS file to rank at the top in the alphabetical order.

    I do realize a solution for this can be to put all the CSS code in a single file (which is actually better for a production environment). But this is pretty inflexible and will make the management of your CSS code quite hard.

  2. URL Rewriting

    This is a major issue, as the CSS files that are added to the website are of a relative path to the real aspx page, not to the URL after it has been rewritten.

    For example if this URL: http://www.example.com/date/category/item.aspx is rewritten from http://www.example.com/items.aspx?id=item. The link to the CSS file inside that page would look like this:

    <link href="App_Themes/ThemeName/style.css" type="text/css" rel="stylesheet" />

    Where it should be: <link href="../../App_Themes/ThemeName/style.css" type="text/css" rel="stylesheet" />

    Or Simply: <link href="http://www.example.com/App_Themes/ThemeName/style.css" type="text/css" rel="stylesheet" />

    Thus breaking the the webpage design, as the browsers will not find the CSS 开发者_Python百科file.

These are the two major issues I have with themes. Thus what I ask, is it a bad move to ditch the App_Themes approach, and switch back to "old school" CSS design (i.e. make a normal folder, put my CSS files in it, and add the links to those CSS manually in my pages)? Is there any feature which I am missing here?


See MSDN for differences between two approaches - essentially, using theme, you can set any properties of controls as opposed to controlling only style. If you are using themes only for styling purposes then you will not be loosing anything going CSS way. I personally found using CSS provides far better control than using built-in themes.


I find that a mix of both approaches works best. When you think of using Theme's, you should only be creating css files, images, skin files that control the look and feel of the site (changing colors or logos, etc) between different themes.

To make sure that the site is structured properly, I always have a base.css, a reset.css, and any other structural css files outside of the theme directory living in it's own folder under the main part of the site (/includes/css/ for example, and /includes/js/ for my javascript).

This way you can ensure that structurally the site will remain consistent and you can always include those css files in a master page, then apply theming to change just the look and feel.

As for the URL re-writing, my link references always start with the / to make sure that the server knows to always start at the root of the server to find the necessary files. So my link for my structural css files would always be:

<link href="/includes/css/base.css" type="text/css" rel="stylesheet" />

HTH.


I think that's better having a separated stylesheet, just for manteinance purposes, and recursivity. If you want to repeat some style, you can easily access to it any time you need it, instead of repeating the code for each styled object. If you want to change the style for several objects, you just change it on the stylesheet and it affects on all the objects!

I hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜