CSS初始化代碼

來源:互聯網
上載者:User

為什麼要初始化CSS?

CSS初始化是指重設瀏覽器的樣式。不同的瀏覽器預設的樣式可能不盡相同,所以開發時的第一件事可能就是如何把它們統一。如果沒對CSS初始化往往會出現瀏覽器之間的頁面差異。每次新開發網站或新網頁時候通過初始化CSS樣式的屬性,為我們將用到的CSS或html標籤更加方便準確,使得我們開發網頁內容時更加方便簡潔,同時減少CSS代碼量,節約網頁下載時間。

CSS初始化範例程式碼

/* css reset www.admin10000.com */
body,p,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { margin:0; padding:0; }
body { background:#fff; color:#555; font-size:14px; font-family: Verdana, Arial, Helvetica, sans-serif; }
td,th,caption { font-size:14px; }
h1, h2, h3, h4, h5, h6 { font-weight:normal; font-size:100%; }
address, caption, cite, code, dfn, em, strong, th, var { font-style:normal; font-weight:normal;}
a { color:#555; text-decoration:none; }
a:hover { text-decoration:underline; }
img { border:none; }
ol,ul,li { list-style:none; }
input, textarea, select, button { font:14px Verdana,Helvetica,Arial,sans-serif; }
table { border-collapse:collapse; }
html {overflow-y: scroll;}
/* css common */
.clearfix:after {content: "."; display: block; height:0; clear:both; visibility: hidden;}
.clearfix { *zoom:1; }

上面是admin10000.com使用的CSS重設代碼,這段代碼是我比較喜歡用的一種方式,雖然還不夠完美但是常用的幾乎已經都包括了。

各主流瀏覽器下的預設css樣式:ie6 | ie7 | ie8 | ie9 | Firefox 3.6.3 | Webkit (r57042) | Opera 10.51

下面順便給出admin10000.com 的html模板,用於每次新開發頁面使用。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn"><head>  <title>網站標題 - Admin10000.com </title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Content-Language" content="zh-CN" /><meta name="Author" content="網頁作者" /> <meta name="Copyright" content="網站著作權" /> <meta name="keywords" content="網站關鍵字" /><meta name="description" content="網站描述" /><link rel="Shortcut Icon" href="網站.ico表徵圖路徑" /><link type="text/css" rel="stylesheet" href="CSS檔案路徑" /><script type="text/javascript" src="JS檔案路徑"></script></head><body></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.