這是2017年不能不了解和學習的一個CSS新特性,非常實用,考慮到現實世界瀏覽器的復雜性,該特性本應該先于其他新特性出來。
我們已經知道使用媒體查詢(Media Query)來檢測屏幕尺寸,從而實現響應式界面設計。
而特性查詢則用來查詢用戶代理(如桌面瀏覽器)是否支持某個CSS3的特性,這個功能除了IE之外,已被其他瀏覽器所支持。
display
: flex ) {
.foo {
display
: flex; }
}
同樣的,和媒體查詢規則類似,可以使用一些邏輯操作符(如and、or和not),并支持串接在一起:
1234567 | @supports ( display : table-cell ) and ( display : list-item ) { … /* your styles */ } @supports not ((text-align-last: justify ) or (-moz-text-align-last: justify ) ){ … /* 不支持justify時,用這里的代碼來模擬text-align-last:justify */ } |
檢測動畫特性:
123456 | @supports (animation-name: test) { … /* 當UA支持無前綴animations特性時的特定樣式 */ @keyframes { /* @supports 作為一個CSS條件組at-rule,可以包含其他at-rules */ … } } |
檢測自定義屬性:
12345 | @supports (--foo: green ) { body { color : green ; } } |
尚處于候選推薦CR(Candidate Recommendation)狀態,規范鏈接:CSS Conditional Rules Module Level 3.
桌面系統:
移動設備:
你可以自己在線試試看。
踏得網原文鏈接
新聞熱點
疑難解答