CSS 區塊層級元素/內嵌元素、繼承與相關屬性簡介

來源:互聯網
上載者:User


什麼是區塊層級元素(Block-level elements)?

  瀏覽器通常在元素之前和之後都使用分行符號顯示區塊層級元素。您可以將其可視化為一堆框。
  區塊層級元素始終在新行上開始,並佔用可用的全寬(儘可能向左和向右擴充)。
用法:區塊層級元素可能只出現在<body>元素內。

什麼是內嵌元素(Inline elements)?

  在HTML中,內嵌元素是僅佔據由定義元素的標籤界定的空格,而不是破壞內容的流。在本文中,我們將檢查HTML內嵌元素以及它們與區塊層級元素的區別。
  內嵌元素不會在新行上啟動,並且只佔用必要的寬度。

什麼是繼承(Inheritance)?

CSS中的繼承是將某些屬性從父元素傳遞給其子項目的機制。
個人理解:父輩有什麼因素,預設遺傳給子輩什麼因素。例子:父母都是黑色頭髮,預設遺傳給孩子黑色頭髮。除非孩子想染灰色頭髮另談,不是該父母的孩子另談。

並不是所有的CSS屬性都是繼承的,因為它們中的一些是沒有意義的。例如,邊距不被繼承,因為子項目不太可能需要與其父元素相同的邊距。在大多數情況下,常識會告訴您哪些屬性是繼承的,哪些屬性不是,但確實需要查看CSS 2.1規範屬性摘要表中的每個屬性。

CSS中可以和不可以繼承的屬性

一、無繼承性的屬性
1、display:規定元素應該產生的框的類型
2、文字屬性:
vertical-align:垂直文本對齊
text-decoration:規定添加到文本的裝飾
text-shadow:文本陰影製作效果
white-space:空白符的處理
unicode-bidi:設定文本的方向
3、盒子模型的屬性:
width、height、margin 、margin-top、margin-right、margin-bottom、margin-left、border、border-style、border-top-style、border-right-style、border-bottom-style、border-left-style、border-width、border-top-width、border-right-right、border-bottom-width、border-left-width、border-color、border-top-color、border-right-color、border-bottom-color、border-left-color、border-top、border-right、border-bottom、border-left、padding、padding-top、padding-right、padding-bottom、padding-left
4、背景屬性:
background、background-color、background-image、background-repeat、background-position、background-attachment
5、定位屬性:
float、clear、position、top、right、bottom、left、min-width、min-height、max-width、max-height、overflow、clip、z-index
6、產生內容屬性:
content、counter-reset、counter-increment
7、輪廓樣式屬性:
outline-style、outline-width、outline-color、outline
8、頁面樣式屬性:
size、page-break-before、page-break-after
9、聲音樣式屬性:
pause-before、pause-after、pause、cue-before、cue-after、cue、play-during

二、有繼承性的屬性
1、字型系列屬性
font:組合字型
font-family:規定元素的字型系列
font-weight:設定字型的粗細
font-size:設定字型的尺寸
font-style:定義字型的風格
font-variant:設定小型大寫字母的字型顯示文本,這意味著所有的小寫字母均會被轉換為大寫,但是所有使用小型大寫字型的字母與其餘文本相比,其字型尺寸更小。
font-stretch:對當前的 font-family 進行伸縮變形。所有主流瀏覽器都不支援。
font-size-adjust:為某個元素規定一個 aspect 值,這樣就可以保持首選字型的 x-height。
2、文本系列屬性
text-indent:文本縮排
text-align:文本水平對齊
line-height:行高
word-spacing:增加或減少單詞間的空白(即字間隔)
letter-spacing:增加或減少字元間的空白(字元間距)
text-transform:控制文字大小寫
direction:規定文本的書寫方向
color:文本顏色
3、元素可見度:visibility
4、表格版面配置屬性:
caption-side、border-collapse、border-spacing、empty-cells、table-layout
5、列表布局屬性:
list-style-type、list-style-image、list-style-position、list-style
6、產生內容屬性:quotes
7、游標屬性:cursor
8、頁面樣式屬性:
page、page-break-inside、windows、orphans
9、聲音樣式屬性:
speak、speak-punctuation、speak-numeral、speak-header、speech-rate、volume、voice-family、pitch、pitch-range、stress、richness、、azimuth、elevation

三、所有元素可以繼承的屬性
1、元素可見度:visibility
2、游標屬性:cursor

四、內嵌元素可以繼承的屬性
1、字型系列屬性
2、除text-indent、text-align之外的文本系列屬性

五、區塊層級元素可以繼承的屬性
1、text-indent、text-alignnce_and_cascade#The_cascade

相關文章

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.