如何测试css属性,如modernizr.js [英] How to test for css properties like modernizr.js

查看:75
本文介绍了如何测试css属性,如modernizr.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想测试浏览器是否支持CSS属性。我知道我可以使用modernizr这样做,但我不想安装一个完整的库来测试一个属性。

I would like to test if a browser supports a CSS property. I know I can use modernizr to do this but I don't want to install an entire library to test for one property.

modernizr如何测试属性?说我想测试支持background-size属性。

How does modernizr test for properties? Say I want to test for support for the background-size property.

我通过文档对象的属性扫描,但看不到任何看起来像它会帮助

I scanned through the properties of the document object but couldn't see anything that looked like it would help.

任何想法或帮助将是巨大的。

Any ideas or help would be great.

推荐答案

Modernizr通过创建一个元素,应用css属性,然后检查css属性的返回值来工作。例如,如果你想测试文本阴影,你可以这样做:

Modernizr works by creating an element, applying a css property and then checking the return value of the css property. For example, if you wanted to test for text shadow you would do this:

if (document.createElement("detect").style.textShadow === "") {
    document.getElementsByTagName("html")[0].className += " textshadow";
}

这篇关于如何测试css属性,如modernizr.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆