2010-04-10 52 views
5

在Firefox,Opera和IE浏览器,我可以通过让他们:如何获得WebKit中所有支持的CSS属性?

>> for (k in document.body.style) console.log(k) 
-> opacity 
    background 
    height 
    textAlign 
    . 
    ... long list ... 
    . 
    pointerEvents

在WebKit的结果是完全不同的:

>> for (k in document.body.style) console.log(k) 
-> cssText 
    length 
    parentRule 
    getPropertyValue 
    getPropertyCSSValue 
    removeProperty 
    getPropertyPriority 
    setProperty 
    item 
    getPropertyShorthand 
    isPropertyImplicit

更新:最新WebKit does enumerate over CSS properties in HTMLElement.style相同方式,所有过浏览器呢。

回答

6

答案是

>> document.defaultView.getComputedStyle(document.body, '') 
-> CSSStyleDeclaration 
    0: "background-attachment" 
    1: "background-clip" 
    2: "background-color" 
    3: "background-image" 
    4: "background-origin" 
    5: "background-position" 
    6: "background-repeat" 
    7: "background-size" 
    8: "border-bottom-color" 
    9: "border-bottom-left-radius" 
    ...

感谢Anton Byrna他solution


一个问题仍然存在:getComputedStyle()不返回像backgroundborder快捷方式。

+0

迭代'document.body.style'提供了Javascript样式属性。 'document.defaultView.getComputedStyle(document.body,'')'只有CSS属性。例如'backgroundAttachment'与'background-attachment'。 – 2012-01-06 10:43:25

+0

以任何方式获得所有可能的值提示,如'继承',百分比,文本底部;为他们每个人。即使使用js。 – 2013-07-07 02:33:15

1

我不确定Javascript的访问权限,但您可以在此查找所有支持的属性(甚至是专有名称):CSS property names

+4

将CSS属性名称的链接更改为http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSPropertyNames.in – 2012-01-06 10:47:30

+0

@Ghodmode谢谢,我解决了我的问题。 – fuxia 2012-01-06 15:35:57