瀏覽器默認標簽樣式總結及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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM