在做樣式設計的時候,切記樣式要從body做起,然後再做body下的元素的樣式,這樣做的好處就是可以確保各個元素之間的連接是無縫的。
在考慮到屏幕大小變化的時候,各個某塊之間的大小及邊距儘量選擇百分比。
引用外部樣式表:
<head>
<link
rel="stylesheet" type="text/css" href="mystyle.css
" />
</head>
定義內部樣式表:
<head>
<style type="text/css">
hr {color: sienna;}
p {margin-left: 20px;}
body {background-image: url("images/back40.gif");}
</style>
</head>
<p style
="color: sienna; margin-left: 20px">This is a paragraph</p>
派生選擇器:
li strong
{ font-style: italic; font-weight: normal; }
<h2>
The strongly emphasized word in this subhead is<strong>
blue</strong>
.</h2>
id選擇器(也可以派生):
#red
{color:red;}
#green
{color:green;}
<p id="red"
>這個段落是紅色。</p>
<p id="green"
>這個段落是綠色。</p>
類選擇器:
.center
{text-align: center}
<h1 class="center"
>This heading will be center-aligned</h1>
屬性選擇器:
input[type="text"]
{width:150px; display:block; margin-bottom:10px; background-color:yellow; font-family: Verdana, Arial;}