什么时候应该使用 ASP.NET 主题,什么时候应该使用 CSS?使用其中一种的优点或缺点是什么?
7 回答
我建议在主题上使用 CSS。这样做的原因是在 CSS 中,您可以修改样式以使其适用于所有浏览器。你可以对主题做同样的事情,但微软的设计师因修复你修复的东西而臭名昭著,以使它们在所有浏览器上都能工作,因此适得其反。坚持使用 CSS,你会花更少的时间在胡闹上。
一起更好!
但是主题不是 CSS 的替代品,或者它们不是为与 CSS 相同的目的而构建的。它的目的是在您的应用程序上定义不同的主题并用一行来更改它们。主题可以包括 CSS 文件、图像文件和皮肤。
使用皮肤,您可以定义 asp.net 控件的样式,因此它包含复杂而完整的解决方案。例如,您可以定义一个 gridview 并定义它的样式和属性。您可以在应用程序范围内定义它。
所以你我认为他们在一起更好,但不等于比较。
If you are considering to hire an external design agency or designer you are much better off with CSS, since CSS is well known to them - since Themes are much more developer/VS centric.
如果您使用会员、个人资料和个性化,主题会非常方便。除此之外,是的,Visual Studio 设计器是臭名昭著的。如果您考虑到浏览器兼容性,则应该广泛使用 CSS。
如前所述,它们并不相互排斥。我有机会拥有多个主题,这些主题本身包含自己的一组 CSS/Media/Skin 文件,这些文件根据站点配置是适当的。
You should combine them. Use your css files in the theme folder for your normal styling of all the html elements in your website (include all the generated elements).
In the skin file of a control, you can set the default css class. Other properties like the layout and default behavior of the elements (sample: calender control) are editable here too.
Skin files are good for all layout specific configuration you can't easily do with css, but with the .net properties of the controls.
Well i would recommend using both together, i use the theme to set the css classes on controls and then style them in the css files. Example:
Skin:
<asp:CompareValidator runat="server" Text="*" CssClass="Validator" Display="Dynamic" />
<asp:RangeValidator runat="server" Text="*" CssClass="Validator" Display="Dynamic" />
<asp:CustomValidator runat="server" Text="*" CssClass="Validator" Display="Dynamic" />
<asp:RegularExpressionValidator runat="server" Text="*" CssClass="Validator" Display="Dynamic" />
<asp:RequiredFieldValidator runat="server" Text="*" CssClass="Validator" Display="Dynamic" />
<asp:ValidationSummary runat="server" CssClass="ValidationSummary" />
Css:
.Validator
{
color: Red;
}
.ValidationSummary
{
font-size: 0.8em;
}
.ValidationSummary > ul
{
list-style-type: disc;
padding: 0 0 0 15px;
margin: 0;
}
.ValidationSummary > ul > li
{
padding: 0;
margin: 0;
color: Red;
}