给服务器控件应用样式
1. 把样式直接应用于HTML元素
使用CSS的第一种方法是直接把样式应用于ASP.NET页面包含的标记上。例如,
<p style="color:blue; font-weight:bold">
Pork chops and applesauce
</p>
2.创建内部样式表
<style type="text/css">
<!--
a:link { text-decoration: none;
color: blue;
}
a:hover { text-decoration: underline;
color: red;
}
a:visited { text-decoration: none;
color: blue;
}
-->
</style>
3.创建外部样式表
4.通过代码向控件应用样式
方法一:直接修改cssclass属性,为其指定类选择器的名字
方法二:利用Attributes属性
方法三: 修改style属性。
Attributes属性
this.Label2.Attributes["Style"] = "color:green; border:solid 1px red;";
通过Style属性
Anchor1.Style["color"] = "red";
Anchor1.Style["font-size"] = "25px";
Anchor1.Style["text-decoration"] = "none";
Anchor1.Style["font-style"] = "italic";