ASP.NET 中主题与 CSS 相比有何优势?

发布于 2024-08-18 13:30:01 字数 176 浏览 2 评论 0原文

由于 ASP.NET 中的主题用于设置网站元素的样式,我只是想知道为什么要使用主题而不是 CSS,或者两者都是常见做法?如果是这样,您什么时候会选择其中一种而不是另一种,为什么?

在我看来,主题是不必要的,所以我只是在寻求澄清,是否确实有充分的理由使用它们,或者它只是框架的一部分,作为网站样式设计的替代(不必要的)步骤。

Since Themes in ASP.NET are used to style elements of your site, I was just wondering why would you use Themes rather than CSS, or is it common practice to use both? If so, when would you opt for one versus the other and why?

Just seems to me like Themes are kind of unnecessary, so I am just looking on clarification if there really is a good reason to use them, or it's just a part of the framework as an alternative(unnecessary) step to styling your site.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-08-25 13:30:01

想象一下,您有一个网站,无论出于何种原因,使用了数十个 asp:Calendar 控件。

要单独使用 CSS 来设置它们的样式,您必须在每个属性上设置大量属性:DayStyle、TitleStyle 和 NextPrevStyle 等等...

使用主题将允许您一次设置所有这些属性,并拥有它适用于网站上的每个 asp:Calendar。主题将包含相同的 CSS,但也包含如何将该 CSS 应用于服务器控件的声明,否则您无法轻松做到这一点。

当然,正如 Brian Hasden 已经说过的,您可能需要一些位于主题之外的“全局”CSS(特别是如果您的网站有多个主题)。

Imagine you have a site that, for whatever reason, uses dozens of asp:Calendar controls.

To style them with CSS alone, you'll have to set loads of properties on each one: DayStyle and TitleStyle and NextPrevStyle and on and on...

Using a theme will allow you to set all of those properties just once, and have it apply to every asp:Calendar on the site. The theme would contain the same CSS, but also the declaration of how to apply that CSS to server controls, which is something you can't easily do otherwise.

Of course, as Brian Hasden already said, you'll probably need some "global" CSS that lives outside of the theme (particularly if your site has multiple themes).

恰似旧人归 2024-08-25 13:30:01

主题的优点是可以紧密集成到整个 .NET 环境中,因此无需指定样式即可获得主题。它像 .NET 中的许多其他事情一样自动发生。基于此,我可以看到对某些人的吸引力。

话虽这么说,我个人从不使用整个主题交易,因为我觉得它需要您维护两组不同的样式。一个是主题的一部分,然后是整个主题交易之外不可避免需要的其他内容。

也许我只是一个控制狂,或者由于以前的项目使用不当而不喜欢主题。

Themes have the benefit of being tightly integrated into the whole .NET environment so that things get themed without needing to specify their styles. It happen automagically like lots of other things in .NET. Based on that I can see the appeal for some people.

That being said, I personally never use the whole themes deal because I feel like it requires you to maintain two different sets of styles. One that's part of the theme and then others that are inevitably needed outside of the whole theming deal.

Maybe I'm just a control freak or dislike themes due to bad usage on previous projects.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文