選擇器 { 屬性: 值; }
h3 { color: blue; }
td {
color: blue;
font-size: 9pt;
}
/* 或多選擇器共用 */
td, p, div {
color: blue;
font-size: 9pt;
}
td { color: blue; font-size: 9pt; }
td { font-family: "標楷體"; line-height: 150%; }
/* 同屬性後宣告者勝出,不同屬性會合併 */
<td style="color:blue; font-size:9pt; font-family:'標楷體'; line-height:150%">
優點:靈活精準;缺點:難維護、無統一性、污染結構。
<style type="text/css">
<!--
body { color: blue; background: #ffffcc; font-size: 9pt; }
td, p { color: green; font-size: 9pt; }
-->
</style>
置於 <head>。優點:單一文件統一;缺點:跨頁複用不便。
<link rel="stylesheet" type="text/css" href="style.css">
置於 <head>。優點:多頁共用、瀏覽器快取、團隊協作;缺點:額外 HTTP 請求(HTTP/2 多路複用已緩解)。
<style type="text/css">
@import url("style.css");
</style>
需在 <style> 內部。缺點:串行載入延遲渲染,現代開發較少用。