DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML和Xhtml
HTML 教學:瀏覽器預設樣式表全解析
編輯:HTML和Xhtml     

很多人以為網頁元素的樣式完全是設計師決定的,其實瀏覽器本身就內建了一份「使用者代理樣式表」。當你的 CSS 沒有指定某項屬性時,最終呈現的樣子就是由這份預設規則決定的。了解它,才能解釋為什麼 <h1> 天生就比較大、<blockquote> 天生就有縮排。

預設樣式的三個重點

第一,顯示類型。html、body、div、p、h1~h6、ul、ol、table 等屬於區塊級元素(display: block);li 是 list-item;table、tr、td 各有 table-row、table-cell 等專屬類型;head 則是 display: none。

第二,外距與行高。body 預設有 8px 邊界、行高約 1.12;h1 的字級是 2em、上下邊距 .67em;p 的邊距是 1.12em;blockquote、ol、ul、dd 則有 40px 的左縮排。

第三,字重與對齊。h1~h6、b、strong 預設為 bolder;th 除了粗體之外還會居中;i、cite、em、var、address 為斜體;s、strike、del 帶刪除線;u、ins 帶底線。

完整預設規則一覽

html, address, blockquote, body, dd, div, dl, dt, fieldset, form, frame, frameset, h1, h2, h3, h4, h5, h6, noframes, ol, p, ul, center, dir, hr, menu, pre { display: block }
li { display: list-item }
head { display: none }
table { display: table }
tr { display: table-row }
thead { display: table-header-group }
tbody { display: table-row-group }
tfoot { display: table-footer-group }
col { display: table-column }
colgroup { display: table-column-group }
td, th { display: table-cell; }
caption { display: table-caption }
th { font-weight: bolder; text-align: center }
caption { text-align: center }
body { margin: 8px; line-height: 1.12 }
h1 { font-size: 2em; margin: .67em 0 }
h2 { font-size: 1.5em; margin: .75em 0 }
h3 { font-size: 1.17em; margin: .83em 0 }
h4, p, blockquote, ul, fieldset, form, ol, dl, dir, menu { margin: 1.12em 0 }
h5 { font-size: .83em; margin: 1.5em 0 }
h6 { font-size: .75em; margin: 1.67em 0 }
h1, h2, h3, h4, h5, h6, b, strong { font-weight: bolder }
blockquote { margin-left: 40px; margin-right: 40px }
i, cite, em, var, address { font-style: italic }
pre, tt, code, kbd, samp { font-family: monospace }
pre { white-space: pre }
button, textarea, input, object, select { display: inline-block; }
big { font-size: 1.17em }
small, sub, sup { font-size: .83em }
sub { vertical-align: sub }
sup { vertical-align: super }
table { border-spacing: 2px; }
thead, tbody, tfoot { vertical-align: middle }
td, th { vertical-align: inherit }
s, strike, del { text-decoration: line-through }
hr { border: 1px inset }
ol, ul, dir, menu, dd { margin-left: 40px }
ol { list-style-type: decimal }
ol ul, ul ol, ul ul, ol ol { margin-top: 0; margin-bottom: 0 }
u, ins { text-decoration: underline }
br:before { content: "\A" }
:before, :after { white-space: pre-line }
center { text-align: center }
abbr, acronym { font-variant: small-caps; letter-spacing: 0.1em }
:link, :visited { text-decoration: underline }
:focus { outline: thin dotted invert }
/* 雙向文字設定(請勿修改) */
BDO[DIR="ltr"] { direction: ltr; unicode-bidi: bidi-override }
BDO[DIR="rtl"] { direction: rtl; unicode-bidi: bidi-override }
*[DIR="ltr"] { direction: ltr; unicode-bidi: embed }
*[DIR="rtl"] { direction: rtl; unicode-bidi: embed }
@media print {
h1 { page-break-before: always }
h1, h2, h3, h4, h5, h6 { page-break-after: avoid }
ul, ol, dl { page-break-before: avoid }

實務上的意義

這份清單解釋了 CSS 重置(reset)為什麼存在:不同瀏覽器的預設值略有出入,若不先把邊距、行高歸零,跨瀏覽器的版面就容易出現落差。反過來說,善用預設值也很省事——例如清單的縮排、表格儲存格的垂直居中,本來就是瀏覽器免費提供的好幫手。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved