::綠細胞雜誌::

Would you like to react to this message? Create an account in a few clicks or log in to continue.

紀錄生活一切雜事


    :::CSS全攻略:::

    grass0423
    grass0423
    Admin


    文章數 : 122
    注冊日期 : 2010-02-23

    :::CSS全攻略::: Empty :::CSS全攻略:::

    發表  grass0423 周五 1月 28, 2011 3:45 pm

    一、CSS的四種實現方式:

    1.內嵌式:
    代碼:
    <style type="text/css">
    <!--
    CSS代碼段
    -->
    </style>

    2.外鏈式:
    代碼:
    <link href="http://blogbeta.blueidea.com/*.css" rel="stylesheet" type="text/css">

    3.導入式
    代碼:
    <style type="text/css">
    <!--
    @import url("*.css");
    -->
    </style>

    4.屬性式:
    代碼:
    <div style="position:absolute; width:200px; height:115px; z-index:1; left: 209px; top: 154px;"></div>

    二.CSS的定義:
    選擇對像{屬性1:值1;屬性2:值2;屬性3:值3;屬性n:值n……}
    如:
    代碼:
    td{font-size:12px;color:#FFFF00}
    .myname{font-size:12px;color:#FFFF00}
    a:hover{font-size:12px;color:#FFFF00;text-decoration: underline;}

    三.四種選擇對像
    1.HTML selector (TagName)
    2.class selector (.NAME)
    3.ID selector (#IDname)
    4.特殊對像 (a:hover a:link a:visited a:active)

    1.HTML selector
    HTML selector就是HTML的置標符,如:DIV、TD、H1。HTML selector的作用範圍是應用了該樣式的所有頁面中的所有該置標符。

    例:
    代碼:
    <html>
    <head>
    <title>藝網CSS教程 作者:木子李</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    td
    {
    color: #FF0000;
    }
    -->
    </style>
    </head>
    <body>
    <table width="300" border="0">
      <tr>
        <td>藝網--ArtHtml.com</td>
      </tr>
      <tr>
        <td>探索民族設計風格 網聚全球藝術精華</td>
      </tr>
    </table>
    </body>
    </html>

    注意:在中沒有應用什麼,其中文字自動變紅色。

    2.class selector
    定義class selector需要往其名稱其加一個點「.」。如「.classname」。class selector的作用範圍是所有包含「class="classname"」的置標符。

    例:
    代碼:
    <html>
    <head>
    <title>藝網CSS教程 作者:木子李</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    .fontRed
    {
    color: #FF0000;
    }
    -->
    </style>
    </head>
    <body>
    <table width="300" border="0">
      <tr>
        <td class="fontRed">藝網--ArtHtml.com</td>
      </tr>
      <tr>
        <td>探索民族設計風格 網聚全球藝術精華</td>
      </tr>
    </table>
    </body>
    </html>

    注意:在第二個中沒有「class="fontRed"」,所以文字沒有變紅色。

    3.ID selector
    定義ID selector需要往其名稱其加一個點「#」。如「#IDname」。ID selector的作用範圍是所有包含「ID="classname"」的置標符。

    例:
    代碼:
    <html>
    <head>
    <title>藝網CSS教程 作者:木子李</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    #fontRed
    {
    color: #FF0000;
    }
    -->
    </style>
    </head>
    <body>
    <table width="300" border="0">
      <tr>
        <td ID="fontRed">藝網--ArtHtml.com</td>
      </tr>
      <tr>
        <td>探索民族設計風格 網聚全球藝術精華</td>
      </tr>
    </table>
    </body>
    </html>

    注意:在第二個中沒有「ID="fontRed"」,所以文字沒有變紅色。

    4.特殊對像
    特殊對像包括四種,是針對鏈接對像設置的:
    a:hover 鼠標移上時的超鏈接
    a:link 常規,非訪問超鏈接
    a:visited 訪問過的超鏈接
    a:active 鼠標點擊時的超鏈接

    特殊對象的作用範圍是所有置標符(這句話有待商榷,因為下面很快就有一種方法可以把「所有」兩個字推翻)。

    例:
    代碼:
    <html>
    <head>
    <title>藝網CSS教程 作者:木子李</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    a
    {
    color: #FF0000;
    }
    a:hover
    {
    color: #0000FF;
    text-decoration: underline;
    }
    -->
    </style>
    </head>
    <body>
    <table width="300" border="0">
      <tr>
        <td><a href="http://www.ArtHtml.com">藝網--ArtHtml.com</a></td>
      </tr>
      <tr>
        <td>探索民族設計風格 網聚全球藝術精華</td>
      </tr>
    </table>
    </body>
    </html>

    注意下面,很有用!!!
    代碼:
    a.classname:hover
    a#IDname:hover
    這兩種寫法,是分別配合.classname與#IDname使用的。它的作用範圍變成了所有包含「class="classname"」或「ID="IDname"」的
    置標符。這種寫法,可以幫助你在同一頁面中實現多種a:hover效果,可以看一下藝網(http://www.ArtHtml.com)http://www.ArtHtml.com)的主頁上導航欄文字與普通文章標題在鼠標時的區別。

    四.應用:
    1.置標符 自動應用
    2.特製類 class="NAME"
    3.ID ID="IDname"
    4.特殊對像 自動應用

    五.CSS屬性
    CSS的屬性有很多,像上文中用到最多的color,表示文字的顏色。background-color表示背景色。這個是最主要的,但是因為沒有什麼難度,參考一下相關手冊就可以了。

      現在的時間是 周四 9月 19, 2024 10:38 am