最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - How do I get all supported CSS properties in WebKit? - Stack Overflow

matteradmin4PV0评论

In Firefox, Opera and IE I can get them via:

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

In WebKit the result is quite different:

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

Update: latest WebKit does enumerate over CSS properties in HTMLElement.style same way all the over browsers do.

In Firefox, Opera and IE I can get them via:

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

In WebKit the result is quite different:

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

Update: latest WebKit does enumerate over CSS properties in HTMLElement.style same way all the over browsers do.

Share Improve this question edited Jan 9, 2012 at 19:53 NVI asked Apr 10, 2010 at 21:01 NVINVI 15.1k17 gold badges68 silver badges104 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

The answer is

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

Thanks to Anton Byrna for his solution.


One problem still remains: getComputedStyle() does not return shortcuts like background and border.

I'm not sure about the Javascript access, but you may look up all supported properties (even the proprietaries) here: CSS property names.

Post a comment

comment list (0)

  1. No comments so far