在ASP.NET怎麼用css?

來源:互聯網
上載者:User

具體的做法可以是:

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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.