主题对比。老派样式表
我使用 ASP.NET 开发网站已经有一段时间了。当我第一次了解主题和皮肤在 ASP.NET 中的工作原理时,我发现它非常棒且简单。
但后来,我开始发现 App_Themes 方法非常烦人,而且我们放入其中的 CSS 根本不灵活。我错过了什么吗?
CSS 文件会使用主题自动添加到 aspx 页面:
当我第一次开始 Web 开发时,我发现这很有帮助。但后来,当我对 CSS 的了解越来越多时,我开始发现这确实令人不安。有时,有一些页面,添加某个CSS文件是没有用的。
最糟糕的是,它总是按字母顺序添加它们,因此您无法控制哪个文件是第一个。如果您已经完成了某种“重置”CSS 文件,这一点尤其重要。因此,命名文件并不总是您想要的,因为您希望重置 CSS 文件按字母顺序排列在顶部。
我确实意识到解决这个问题的方法是将所有 CSS 代码放在一个文件中(这实际上更适合生产环境)。但这非常不灵活,并且会使 CSS 代码的管理变得相当困难。
URL重写
这是一个主要问题,因为添加到网站的 CSS 文件是真实 aspx 页面的相对路径,而不是重写后的 URL。
例如,如果此 URL:http://www.example.com/date/ category/item.aspx 重写自 http://www.example.com /items.aspx?id=item。该页面内 CSS 文件的链接如下所示:
它应该在哪里:
或者简单地说:
因此破坏了网页设计,因为浏览器将找不到 CSS 文件。
这是我对主题的两个主要问题。因此,我要问的是,放弃 App_Themes 方法并切换回“老式”CSS 设计(即创建一个普通文件夹,将我的 CSS 文件放入其中,然后在我的文件夹中手动添加这些 CSS 的链接)是一个糟糕的举动吗?页)?我这里缺少什么功能吗?
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?
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.
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅 MSDN 了解两种方法之间的差异 - 本质上是使用主题,您可以设置控件的任何属性,而不是仅控制样式。如果您仅将主题用于样式目的,那么您不会丢失任何 CSS 方式的内容。我个人发现使用 CSS 比使用内置主题提供更好的控制。
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.
我发现两种方法的结合效果最好。当您考虑使用主题时,您应该只创建 css 文件、图像、皮肤文件来控制不同主题之间网站的外观和感觉(更改颜色或徽标等)。
为了确保网站的结构正确,我总是有一个base.css、一个reset.css以及主题目录之外的任何其他结构CSS文件,这些文件位于网站主要部分下的自己的文件夹中(/includes/例如,我的 css/ ,以及我的 javascript 的 /includes/js/ )。
通过这种方式,您可以确保站点在结构上保持一致,并且您始终可以将这些 css 文件包含在母版页中,然后应用主题来更改外观和感觉。
至于 URL 重写,我的链接引用始终以 / 开头,以确保服务器知道始终从服务器的根目录开始查找必要的文件。所以我的结构 css 文件的链接始终是:
HTH。
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:
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.