
- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 行內塊
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - 清除浮動
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 定位
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 焦點
- CSS - 縮放
- CSS - 位移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 覆蓋層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪下
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - 內嵌
- CSS - 隔離
- CSS - 溢位滾動
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大塊級尺寸
- CSS - 最小塊級尺寸
- CSS - 混合模式
- CSS - 最大內聯尺寸
- CSS - 最小內聯尺寸
- CSS - 偏移
- CSS - 口音色
- CSS - 使用者選擇
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - !important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - 盒裝飾中斷
- CSS - 游標顏色
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特效性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX到EM轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - all 屬性
CSS all 屬性重置元素的所有屬性,但以下屬性除外:unicode bidi、direction 和 CSS 自定義屬性。它可以將屬性重置為其原始值或繼承值,也可以重置為在另一個級聯層或樣式表源中顯式定義的值。
語法
all: initial | inherit | unset;
屬性值
值 | 描述 |
---|---|
initial | 它將應用於元素或其父元素的所有屬性更改為其初始值。 |
inherit | 它將應用於元素或其父元素的所有屬性更改為其父元素的值。 |
unset | 如果屬性可繼承,則將其更改為父元素的值;如果不可繼承,則更改為其初始值。 |
CSS all 屬性示例
以下示例說明了使用不同值的 all 屬性。
使用 initial 值的 all 屬性
要使元素的屬性設定為瀏覽器分配的預設值,以便沒有定義的樣式適用於它們,我們使用 initial 值。這在以下示例中顯示。
示例
<!DOCTYPE html> <html> <head> <style> html { font-size: 25px; color: lightcoral; font-style: italic; } #custom1 { background-color: #ecf0f1; color: #e74c3c; } #custom2 { all: initial; } </style> </head> <body> <h2> CSS all property </h2> <div id="custom1"> See how this sentence changes!- This is reference sentence </div><br/> <div id="custom2"> See how this sentence changed. This sentence is using initial value so it does not inherit anything from its parent element or html element, this is evident from the text style and color. </div> </body> </html>
使用 inherit 值的 all 屬性
要使元素的屬性設定為其父元素或 html 元素的屬性,則我們使用 inherit 值。如果存在父元素定義的屬性,則將應用這些屬性;如果不存在,則將應用 html 元素屬性。這在以下示例中顯示。
示例
<!DOCTYPE html> <html> <head> <style> html { font-size: 25px; color: lightcoral; font-style: italic; } #custom1 { background-color: lightgreen; font-weight: bold; padding: 10px; color: #e74c3c; } #custom2 { all: inherit; } </style> </head> <body> <h2> CSS all property </h2> <div id="custom1"> See how this sentence changes!- This is reference sentence </div><br/> <div id="custom2"> See how this sentence changed. This sentence is using inherit value so it inherits the properties from its parent or from the html element, in this case the html element. It has inherited font-size, color and font-style. </div> </body> </html>
使用 unset 值的 all 屬性
要使元素的屬性從其父元素(如果存在)或 html 元素(如果不存在)或瀏覽器決定的預設值(在兩者都不存在的情況下表現得像 initial)中獲取,則我們使用 unset 值。這在以下示例中顯示。
示例
<!DOCTYPE html> <html> <head> <style> .parent { color: purple; font-weight: bold; font-size: 20px; text-align: center; background-color: lightgrey; } .custom1 { font-weight: bold; padding: 10px; } .custom2 { all: unset; } </style> </head> <body> <h2> CSS all property </h2> <div class="parent"> <div class="custom1"> This sentence is using the 'unset' value and also has a parent, so it inherits the parent properties. </div> </div> <br/> <div class="custom2"> This sentence is also using the 'unset' value but it doesnt have a parent, so it follows the initial value getting default values. </div> </body> </html>
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
all | 37.0 | 79.0 | 27.0 | 9.1 | 24.0 |
廣告