在asp.net页面中动态导入css最简单的方法

[ 2005-09-13 19:59:43 | 作者: bdboy ]

======================= 1 ========================

<link href ="" rel="stylesheet" type="text/css" id="cssStyle" runat="server" />
c# code:
[ Copy ] [ Run ] [ Save As ]
<script runat="server">
void Page_Load()
{
//...
cssStyle.Attributes["href"]="style1.css";//Import another css file.
//...
}
</script>

下面是通过超链接导入:
<script runat="server">
 void Page_Load(object sender, EventArgs e)
 {
 if (Request.QueryString["css"] == null)
 {
 cssStyle.Attributes["href"] = @"./css/blueberry.css";
 }
 else
 {
 cssStyle.Attributes["href"] = @"./css/" + Request.QueryString["css"] + ".css";
 }
 }
</script>
<a href="./Default.aspx?css=slate">slate, </a>

CSS 文件的样例代码:
<style type="text/css">
<!—
br{ background-image: url(http://Fred.com/ImageFile/Q.gif); background-position: top right; background-repeat:no-repeat; }
p { text-indent: 2em}
body { font-family: "宋体"; font-size: 12px; color: #000000; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px}
table { line-height: 20px;}
a:link { text-decoration: none}
a:visited { text-decoration: none}
a:hover { text-decoration: underline}
a:active { text-decoration: none}
a.1:link { font-size: 10px; color: #oooooo; text-decoration: none}
a.1:visited { font-size: 10; color: #3366cc; text-decoration: none}
.blue {font-style: italic; font-size: 10.5pt; line-height: 20px; letter-spacing: 5em; font-weight:bold}
.h1{font: italic bold "Arial"; word-spacing : 10px}
-->
</style>
 
这里尤其要注意的是a:link a:visited a:hover a:actived 的排列顺序一定要严格照上面的样例代码,否则或多或少会出问题。另外我们规定重定义的最先,伪类其次,自定义最后,便于自己和他人阅读!
新闻类网站css规范
<style type="text/css">
<!--
/* ============== */
/* 以下是标签样式 */
/* ============== */
body {
font-size: 12px;
color: #000000;
background-color: #FFFFFF;
text-align: center;
margin: 0px;
padding: 0px;
font-family: "Verdana", "song";
}
td {
font-size: 12px;
}
form {
margin: 0px;
padding: 0px;
}
a:link { color: #000000; text-decoration: none;}
a:visited { color: #000000; text-decoration: none;}
a:hover { color: #000000; text-decoration: underline;}
a:active { color: #000000; text-decoration: none;}
/* ================ */
/* 以下是自定义样式 */
/* ================ */
.Nav {
color: #FFFFFF;
text-align: center;
}
.Nav a:link { color: #FFFFFF; text-decoration: none;}
.Nav a:visited { color: #FFFFFF; text-decoration: none;}
.Nav a:hover { color: #FFF000; text-decoration: underline;}
.Nav a:active { color: #FFFFFF; text-decoration: none;}/* 导航条文字、链接样式 */
.FormStyle1 {
border: 1px solid #A4A4A4;
margin: 0px;
padding: 2px;
width: 70px;
font-family: "Verdana", "song";
background-color: #FDBE25;
font-size: 12px;
letter-spacing: 6px;
}/* 用户名密码input样式 */
.TopImgNews td {
font-size: 14px;
font-weight: bold;
text-align: center;
letter-spacing: 3px;
}/* 图片头条文字样式 */
.NavBox1 {
background-color: #DFF3E5;
padding-left: 10px;
border-top-width: 1px;
border-bottom-width: 2px;
border-top-style: dotted;
border-bottom-style: solid;
border-top-color: #000000;
border-bottom-color: #000000;
padding-top: 3px;
padding-bottom: 3px;
}/* 信息页导航所在的表格样式 上虚线 下实线 */
.contenttitle {
line-height: 150%;
text-align: center;
font-size: 26px;
color: #24580E;
padding-top: 15px;
}/* 信息页新闻标题 */
.contentword {
line-height: 150%;
font-size: 14.8px;
}/* 信息页正文 */
-->
</style>

posted on 2005-11-01 10:25  扎悉的乐  阅读(964)  评论(0)    收藏  举报

导航