2010-04-10 22 views
5

In Firefox, Opera e IE li posso ottenere tramite:Come ottengo tutte le proprietà CSS supportate in WebKit?

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

in WebKit il risultato è ben diverso:

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

Aggiornamento: ultima WebKit does enumerate over CSS properties in HTMLElement.style stesso modo tutti gli oltre i browser lo fanno

risposta

6

La risposta è

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

Grazie a Anton Byrna per la sua solution.


Un problema rimane: getComputedStyle() non restituisce le scorciatoie come background e border.

+0

Iterating 'document.body.style' fornisce le proprietà di stile Javascript. 'document.defaultView.getComputedStyle (document.body, '')' ha solo le proprietà CSS. per esempio. 'backgroundAttachment' vs.' background-attachment'. –

+0

un modo per ottenere tutti i loro possibili suggerimenti di valori come 'inherit', percentuale, text-bottom; per ognuno di loro. anche se si usa js. –

1

Non sono sicuro dell'accesso Javascript, ma è possibile cercare tutte le proprietà supportate (anche le proprietà) qui: CSS property names.

+4

Link per i nomi di proprietà CSS modificati in http://trac.webkit.org/browser/trunk/Source/WebCore/css/CSSPropertyNames.in –

+0

@Ghodmode Grazie, ho risolto la mia risposta. – fuxia

Problemi correlati