在.asp中如何引用CSS样式表?

html-css029

在.asp中如何引用CSS样式表?,第1张

可以定义一个类:

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}

比如说 我要用图片中的layout.css

那么 在你的页面源代码中head标记之间

<head>

<link href="css/layout.css" rel="stylesheet" type="text/css" />

</head>

然后你的整个页面都将套用layout.css样式

若layout.css中定义了名称为td的样式

你在用的时候只需要将元素的Class=”td“即可

样式表layout.css中格式为

.名称{

样式1

样式2

}

样式可以在右侧属性里通过视图添加  也可手写。