现在的位置: 首页 > 综合 > 正文

在ASP.NET怎么用css?

2013年09月03日 ⁄ 综合 ⁄ 共 2150字 ⁄ 字号 评论关闭

具体的做法可以是:

1 使用theme,右击网站名字,选asp.net文件夹,并选App_Themes,添加主题,不取中文名,如theme1
2 右击themes,新建项,选css,
3 将代码拷入:(不需写样式的头和尾)
.fu1 {
font-size: 12px;
color:red;
font-family:"仿宋_GB2312"
}
.fu2 {
font-size: 12px;
line-height: 20px;
color: #0033CC;
}
a.ok:link {
font-size: 12px;
color: #993300;
text-decoration: none;
}
a.ok:hover {
font-size: 12px;
color: #FF99CC;
text-decoration: none;
}
a.ok:active {
font-size: 12px;
color: #6699CC;
text-decoration: none;
}
a.ok:visited {
font-size: 12px;
color: #CC3333;
text-decoration: none;
}
a:link {
font-size: 12px;
color: #0066CC;
text-decoration: none;
}
a:hover {
font-size: 12px;
color: #009900;
text-decoration: none;
}
a:active {
font-size: 12px;
color: #0066CC;
text-decoration: none;
}
a:visited {
font-size: 12px;
color: #0033CC;
text-decoration: none;
}
table {
color: #FF9900;
background-color: #CCCCCC;
}
4 在需要用的页面的源视图第一行代码中加入:
theme=theme1
5 最在要用的控件上
<asp:Label ID="Label1" runat="server" Text="用户名:" CssClass="fu1" ></asp:Label>

还可以到网上找个CSS样式的文件

直接复制放到项目中

比如说名称为maing.css

然后在要用到这个样式的页面中加上这句话就搞定了
<link href="main.css" rel="stylesheet" type="text/css">

管理样式 ( CSS )
  1.三种嵌入样式表的方法:
    //在头部统一声明样式
    <style type="text/css"> body{ font-size:9pt; } </style>
    
    //从外部嵌入一样式表文件
    <link rel="stylesheet" type="text/css" href="myStyleSheet.css">
    
    //直接在元素属性里定义
    <p style="font-size:9pt"></p>
    
  2.分配样式规则给某一元素
    <style type="text/css">
        <!-- tagName {styleProperty1:value1; styleProperty2:value2; ...} -->
    </style>
    
  3.自定义一种样式供一类元素使用
    .myStyle { font-size:9pt; }
    <p class="myStyle"></p>
    
  4.自定义一种样式供单一元素使用
    #myId { font-size:9pt; }
    <p id="myId"></p>
    
  5.页面加载后动态修改页面样式表链接
    <link id="basicStyle" rel="stylesheet" type="text/css" href="styles.normal.css">
    document.getElementById("basicStyle").href = "newstyle.css";
    
  6.打开/关闭某个样式表
    document.styleSheets[1].disabled = false;
    
  7.动态设置/更改某一元素的样式
    document.getElementById("myElement").className = "myStyle";
    
  8.元素样式的优先级
    //原则上来讲,浏览器会使用最后的一种样式(就近原则)
    //当同时给一元素设置id和class两种样式时,id的样式优先于class
    //当同时给一元素设置class和style两种样式时,style优先于class
    //当同时给一元素设置style和id两种样式时,style优先于id
    <style>
        .myStyle { font-size:10pt; }
        #myId { font-size:11pt; }
    </style>
    <p id="myId" class="myStyle" style="font-size:12pt">123</p>

【上篇】
【下篇】

抱歉!评论已关闭.