CSS學習: 編寫CSS檔案

來源:互聯網
上載者:User
根據在HTML檔案中CSS樣式表的位置, 將CSS檔案分為: 頭部CSS, 主體CSS, 外部CSS
1. 編寫頭部CSShead
<html>
<head>
<style type="text/css">
<!--
h3{color:black; font-size:35px; font-family:黑體}
p{background:yellow; color:red; font-family:宋體}
-->
</style>
<title>編寫頭部CSS檔案</title>
</head>
<body>
<h3 align="center">編寫頭部CSS檔案</h3>
<hr>
<p>
在HTML檔案的頭部應用內部樣式表方法添加CSS.
</p>
</body>
</html>

2. 編寫主體的CSSbody
<html>
<head>
<title>編寫主體CSS檔案</title>
</head>
<body>
<center>
<h1 style="color:green;font-size:35px;font-family:黑體">編寫主體CSS檔案</h1>
</center>
<hr>
<p style="background:cyan;color:red;font-size:25px;font-family:隸書">
在HTML檔案的主體應用嵌入式樣表方法添加CSS.
</p>
</body>
</html>

3. 編寫外部的CSS
(1). 應用鏈入外部樣式表方法在HTML檔案內調用外部定義的CSS檔案
CSS代碼:<!CSS檔案的代碼>
<style type="text/css">
<!--
h3{color:black;font-size:35px;font-family:黑體}
p{background:orange;color:blue;font-size:25px;font-family:隸書}
-->
</style>

HTML代碼:Html
<html>
<head>
<title>編寫外部CSS檔案</title>
<link rel=stylesheet type="text/css" href="niuniu1.css">
</head>
<body>
<h3 align="center">編寫外部CSS檔案</h3>
<hr>
<p>在HTML檔案應用鏈入外部樣式表方法調用外部CSS.</p>
</body>
</html>

(2). 應用匯入外部樣式表方法在HTML檔案內調用外部定義的CSS檔案

字型的設定
font-family: 字型  可以一次定義多個字型.
font-size:字型大小
font-style:字型樣式  normal,italic, oblique(正常,斜體,歪斜體)
font-weight:字型加粗 normal,bold,bolder,lighter,number
font-variant:字型變體 normal,small-caps(英文字型顯示為小型的大寫字母)

font:組合設定字型屬性
font屬性是一種複合屬性, 可以同時對文字設定多個屬性.
基本文法:
font: font-family|font-size|font-style|font-weight|font-variant
如: p{font: italic bold small-caps 15pt/18pt 宋體;} 屬性之間要用空格間隔開.
執行個體:Code
<html>
<head>
<title>綜合設定字型執行個體</title>
<style type="text/css">
<!--
h3{font-family:黑體;font-size:25px;font-weight:bolder}
.p1{font:italic samll-caps 15pt/20pt 宋體;}
-->
</style>
</head>
<body>
<center>
<h3>CSS基本概念</h3>
</center>
<hr>
CSS(Cascading Style Sheet)即層疊樣式表, 簡稱樣式表.<br>
<p class=p1>CSS(Cascading Style Sheet)即層疊樣式表, 簡稱樣式表. </p>
</body>
</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.