static public class AddStyle{
static public void AddStyleSheet(Page page, string cssPath)
{
HtmlLink link = new HtmlLink()
link.Href = cssPath
link.Attributes["rel"] = "stylesheet"
link.Attributes["type"] = "text/css"
page.Header.Controls.Add(link)
}
}
然后在页面中调用该类的静态方法:
在page_load方法中:
protected void Page_Load(object sender, EventArgs e)
{
AddStyle.AddStyleSheet(this.Page, "css/test.css")
//CSS文件放在这里.
}
这个不是说asp中如何设置,而是看你要对某个div层进行什么样式设置,就是纯粹的css样式写法而已,然后通过css外部引入<link href="other.css" rel="stylesheet" type="text/css" />
例如,下面我要写个面包屑,对外框div层写入总体样式,12号字体,#333的颜色,行高24px当前页的样式cur颜色为蓝色等等,
about.asp
<div class="crumbs">
<a href="/">Home</a>>
<h1 class="cur">About</h1>
</div>
other.css写入
.crumbs{ height:24pxline-height:24pxcolor:#333font-size:12px}
.crumbs h1.cur{ color:blue}
不太明白你的意思?外部样式可以新建一个css文件夹添加一个后缀名为.css的文件,在head可以这样引用:<link href="css/index.css" type="text/css" rel="stylesheet" />
内部样式可以:
<style type="text/css>
a{color:red}
a:hover{color:green}
.border{border:1px solid #CCC}//class
#content_left{background:url(img/c_left.jpg)}//id
</style>
内嵌样式可以:
<p style="color:blue"><span style="font-size:20pxcolor:#FFF">啊!</span>不错的风格</p>