ASP.NET中内容页如何调用CSS样式?

html-css029

ASP.NET中内容页如何调用CSS样式?,第1张

你说的是asp.net2.0中引用了模板页的页面吧:你可以定义一个类:

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文件放在这里

}

直接引用css放在第一个content里面就可以了

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<title>昂旺电子商务网站-首页</title>

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

<script src="js/banner.js" type="text/javascript"></script>

<script type="text/javascript">

//<![CDATA[

$(document).ready(function () { $('#image_rotate').innerfade({ speed: 1500, timeout: 3000, type: 'sequence', containerheight: '380px' })})

//]]>

</script>

</asp:Content>

<link rel="Stylesheet" media="screen" href="../css.css" />

把css写成一个单独的页面,然后在页面里面用这个语句直接调用。