CSS進階之路

來源:互聯網
上載者:User

標籤:size   column   多少   cap   對齊   bottom   ddl   問題   under   

下面主要引用http://www.cnblogs.com/wangfupeng1988/tag/css知多少/

CSS進階筆記:

一、學習CSS的三個突破點

1.瀏覽器如何載入和解析CSS——CSS的5個來源;

2.CSS和html如何結合起來——選取器;

3.CSS能控制那些顯示方式——盒子模式、浮動、定位、背景、字型等;

下面分開闡述:

1.瀏覽器如何載入和解析CSS

(1) 瀏覽器預設樣式表

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 }/*以上列表元素預設狀態下一塊狀顯示,未顯示的將以內嵌元素顯示,該列錶針對HTML4版本,部分元素在XHTML1中將廢棄*/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 }/*定義sub元素預設為下標顯示*/sup { vertical-align: super }/*定義sub元素預設為上標顯示*/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 }/*定義分割線預設為1px寬的3D凹邊效果*/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 } /* Begin bidirectionality settings (do not change) */BDO[DIR="ltr"] { direction: ltr; unicode-bidi: bidi-override }/*定義BDO元素當其屬性為DIR="ltr"時的預設文本讀寫顯示順序*/BDO[DIR="rtl"] { direction: rtl; unicode-bidi: bidi-override }/*定義BDO元素當其屬性為DIR="rtl"時的預設文本讀寫顯示順序*/*[DIR="ltr"] { direction: ltr; unicode-bidi: embed }/*定義任何元素當其屬性為DIR="ltr"時的預設文本讀寫顯示順序*/*[DIR="rtl"] { direction: rtl; unicode-bidi: embed }/*定義任何元素當其屬性為DIR="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 }}
瀏覽器預設樣式

(2) 使用者樣式表(不常用)

(3) <link>引用的css檔案

(4) <style>中編寫的樣式代碼

(5) <a style=’ ’>中編寫的樣式代碼

2.常見問題:

(1) 不同瀏覽器預設樣式不一致

解決方案:* {margin:0; padding:0;}

(2) 層疊錯誤

首先得知道層疊規則:

瀏覽器會把各個零散的整合成一個整體,瀏覽器會讓後者覆蓋前者;特殊情況——!imporment(最高執行權,後面層疊不會影響它)

Demo如下:

   

3.差異比較

(1) div {display:block}(預設)、table{display:table}、td,th{display:table-cell}

a. div寬度和父容器相同,table寬度根據內容而定——即table具有“包裹性”;

b. table-cell 用法舉例:

      

  用table-cell,像用table一樣做多欄版面配置,做出來的效果和table做出來的效果是一模一樣的;

 

CSS進階之路

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.