Possible to get the source of a CSS style?

30 views
Skip to first unread message

Scott Mueller

unread,
Jan 27, 2017, 3:22:17 AM1/27/17
to phantomjs

In an exercise system, I want to make sure students are entering their CSS rules in the correct place. Is there any way, in PhantomJS, to know where a CSS style came from?

For example, I want to know that an element is red because that CSS property came from an external stylesheet called index.css and not from an internal stylesheet.

mic...@mwarddev.com

unread,
Jun 29, 2017, 12:33:41 AM6/29/17
to phantomjs
I'm not sure if this helps, but you can use the Javascript 
getComputedStyle(element, [psuedoElement..])
function to return the properties of a given object. 

A very important piece of information to consider is that the returned style object is read-only, and is the complete collection of styles of the node. Ie, if you say "font: SomeReallyCrazyFont" on <body>, calling getComputedStyle on a child element which doesn't have any explicitly defined font will contain "SomeReallyCrazyFont" as it's font property.
Reply all
Reply to author
Forward
0 new messages