CSS教程之CSS的應用

來源:互聯網
上載者:User

一、In-line 行內

  行內樣式是在html標籤裡直接使用style屬性

<p style="color: red">text</p>
  設定段落文字紅色。
  但要記住,最後的HTML應該是獨立出來,使用表現文檔,所以行內樣式應該在任何地方避免。

二、Internal 內部

  使用於整個頁面的植入內部樣式在head標籤裡面,style標籤包圍樣式。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>CSS Example</title>
<style type="text/css">
p {

color: red;
}

a {
color: blue;
}
</style>
...
  所有段落文字紅色,連結藍色。
  像行內樣式一樣,你應該保持HTML和CSS分離,所以我們只剩下救星。

三、外部

  外部樣式使用在整個多樣頁面網站。它是一個獨立的CSS檔案,像下面一樣:

p {
color: red;
}

a {
color: blue;
}
  如果上面儲存為“web.css”,HTML裡面的連結就像下面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>CSS Example</title>
<link rel="stylesheet" type="text/css" href="web.css" />
...
  後面教程裡會講到其他外聯樣式的方法,現在已經足夠了。

  從這篇指導裡面,我們以後沿著上面的方法實驗代碼是個好主意,用文字編輯器建立檔案,儲存為"web.css"在html目錄。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My first web page</title>
<link rel="stylesheet" type="text/css" href="web.css" />
</head>
...
  儲存HTML檔案,現在已經連結上CSS,不過現在CSS是空的,沒有內容不會改變HTML。當你開始學習CSS,就可以添加代碼到CSS檔案裡,看HTML重新整理後的結果。

相關文章

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.