Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSS 属性兼容性判断方法 #76

Open
nmsn opened this issue Jan 2, 2023 · 1 comment
Open

CSS 属性兼容性判断方法 #76

nmsn opened this issue Jan 2, 2023 · 1 comment
Labels

Comments

@nmsn
Copy link
Owner

nmsn commented Jan 2, 2023

如题

@nmsn nmsn added the CSS label Jan 2, 2023
@nmsn
Copy link
Owner Author

nmsn commented Jan 2, 2023

CSS

@supports <条件规则> {
  /* 特殊样式规则 */
}

eg:

@supports (display:flex) {
  section { display: flex }
  ...
} 

意思就是如果支持 display: flex 的话,就在 section 中应用

JS

在 window 上提供方法 CSS.supports('属性', '属性值')

eg:

const  supportsFlex = CSS.supports("display", "flex");    

当然,使用前先判断下兼容性如何

var supportsCSS = !!((window.CSS && window.CSS.supports) || window.supportsCSS || false);   

// window.supportsCSS 为旧版 api

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant