瀏覽器預設標籤樣式總結及css初始化程式,css初始化

來源:互聯網
上載者:User

瀏覽器預設標籤樣式總結及css初始化程式,css初始化

  html中的大部分的標籤都有一些糟糕的樣式,有的是標籤天然內建的,有的是瀏覽器預設設定的,我們在寫網頁時,這些預設的樣式就會時不時的跳出來搗一下亂,搞得我們很是無奈。所以成手在寫css樣式時,一般都會在開頭寫一段初始化程式,來去掉這些預設樣式,比如最簡單的方法就是使用*{margin:0;padding:0;}。但是通常我們很少使用這種方法,因為萬用字元*的效率極低。那我們應該使用哪種方法呢,下面博主就來為大家介紹一些常用的方法。

一、瀏覽器預設樣式總結

  在介紹初始化程式之前,我們先瞭解一下都有那些標籤被設定了哪些預設樣式,只有瞭解清楚了這些,我們才能更好的對標籤樣式初始化。

(一)、標籤內建樣式
//區塊層級元素html, body,  div,ol, p, ul,  h1, h2,h3,h4,h5, h6, address,blockquote, form,dd,dl, dt, fieldset, frame, frameset,noframes,center, dir, hr, menu, pre   { display: block }//列表元素類li{ display:list-item }ol{list-style-type: decimal }ol ul, ul ol,ul ul, ol ol  { margin-top: 0; margin-bottom: 0 }ol, ul{ margin-left: 40px }//預格式文本類i, cite, em,var, address{ font-style: italic }big{ font-size:1.17em }small, sub, sup{ font-size: .83em }sub{ vertical-align:sub }sup{ vertical-align:super }s, strike, del{ text-decoration: line-through }u, ins{ text-decoration:underline }//標題類 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 }//偽類br:before{ content: ”\A” }:before, :after{ white-space: pre-line }:link, :visited { text-decoration: underline }:focus{ outline: thin dotted invert }//表格類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 }table{ border-spacing: 2px;}thead, tbody,tfoot { vertical-align:middle }td, th { vertical-align:inherit }//其它元素head{ display: none }body{ margin: 8px;line-height: 1.12 }      button, textarea,input, object,select  { display:inline-block;}blockquote{ margin-left: 40px;margin-right: 40px }pre, tt, code,kbd, samp  { font-family: monospace }pre{ white-space: pre}hr{ border: 1px inset }center{ text-align: center }abbr, acronym{ font-variant: small-caps; letter-spacing:0.1em } BDO[DIR="ltr"]  { direction: ltr; unicode-bidi:bidi-override } BDO[DIR="rtl"]  { direction: rtl; unicode-bidi:bidi-override } /*定義BDO元素當其屬性為DIR="ltr/rtl"時的預設文本讀寫顯示順序*/ *[DIR="ltr"]{ direction: ltr;unicode-bidi: embed } *[DIR="rtl"] { direction: rtl;unicode-bidi: embed } /*定義任何元素當其屬性為DIR="rtl/rtl"時的預設文本讀寫顯示順序*/ @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初始化往往會出現瀏覽器之間的頁面差異。

  1.頁面邊界

    IE預設為10px,通過body的margin屬性設定
    FF預設為8px,通過body的padding屬性設定

  2.段間距

    IE預設為19px,通過p的margin-top屬性設定
    FF預設為1.12em,通過p的margin-bottom屬性設

  3.標題樣式

    h1~h6預設加粗顯示:font-weight:bold;
    預設大小請參上表
    還有是這樣的寫的

h1 {font-size:xx-large;} h2 {font-size:x-large;} h3 {font-size:large;} h4 {font-size:medium;} h5 {font-size:small;} h6 {font-size:x-small;}

  4.列表樣式
    IE預設為40px,通過ul、ol的margin屬性設定
    FF預設為40px,通過ul、ol的padding屬性設定
    dl無縮排,但起內部的說明元素dd預設縮排40px,而名稱元素dt沒有縮排。

  5.元素置中

    IE預設為text-align:center;

    FF預設為margin-left:auto;margin-right:auto;

  6.超連結<a>樣式

    a 樣式預設帶有底線,顯示顏色為藍色,被瀏覽過的超連結變紫色

  7.滑鼠樣式

    IE預設為cursor:hand;

    FF預設為cursor:pointer;該聲明在IE中也有效

 

  8.圖片連結樣式
    IE預設為紫色2px的邊框線
    FF預設為藍色2px的邊框線  

二、css初始化程式

  博主總結了一些初始化的代碼,博友們可以參考一下,具體使用時可以適當地刪減一些。

@charset "UTF-8";/*css 初始化 */html, body, ul, li, ol, dl, dd, dt, p, h1, h2, h3, h4, h5, h6, form, fieldset, legend, img {    margin: 0;    padding: 0;}fieldset, img, input, button {    border: none;    padding: 0;    margin: 0;    outline-style: none;}ul, ol {    list-style: none;}input {    padding-top: 0;    padding-bottom: 0;    font-family: "SimSun", "宋體";}select, input {    vertical-align: middle;}select, input, textarea {    font-size: 12px;    margin: 0;}textarea {    resize: none;}/*防止拖動*/img {    border: 0;    vertical-align: middle;}/*  去掉圖片低測預設的3像素空白縫隙*/table {    border-collapse: collapse;}body {    font: 12px/150% Arial, Verdana, "\5b8b\4f53";    color: #666;    background: #fff}h1, h2, h3, h4, h5, h6 {    text-decoration: none;    font-weight: normal;    font-size: 100%;}s, i, em {    font-style: normal;    text-decoration: none;}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.