2010-04-10 5 views
5

Dans Firefox, Opera et IE je peux les obtenir via:Comment obtenir toutes les propriétés CSS prises en charge dans WebKit?

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

En WebKit le résultat est tout à fait différent:

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

Mise à jour: dernière WebKit does enumerate over CSS properties in HTMLElement.style même tous les plus les navigateurs font.

Répondre

6

La réponse est

>> 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" 
    ...

Merci à Anton Byrna pour son solution.


Un problème reste: getComputedStyle() ne retourne pas de raccourcis comme background et border.

+0

L'écriture de 'document.body.style' fournit les propriétés de style Javascript. 'document.defaultView.getComputedStyle (document.body, '')' a seulement les propriétés CSS. par exemple. 'backgroundAttachment' vs.' background-attachment'. –

+0

de toute façon pour obtenir toutes leurs indications possibles de valeurs comme «hériter», le pourcentage, le texte en bas; pour chacun d'eux. même si j'utilise js. –

1

Je ne suis pas sûr de l'accès Javascript, mais vous pouvez rechercher toutes les propriétés supportées (même les propriétaires) ici: CSS property names.

+4

Le lien pour les noms de propriété CSS a été changé en http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSPropertyNames.in –

+0

@Ghodmode Merci, j'ai corrigé ma réponse. – fuxia