Skip to content

Instantly share code, notes, and snippets.

@thinsoldier
Last active November 26, 2015 18:42
Show Gist options
  • Save thinsoldier/2b0b86d20920f8d52e22 to your computer and use it in GitHub Desktop.
Save thinsoldier/2b0b86d20920f8d52e22 to your computer and use it in GitHub Desktop.
How to extract computed style of dom nodes as text that can be compared in a text editor.
function logComputedStyles(elem,prop) {
var cs = window.getComputedStyle(elem,null);
if (prop) {
console.log(" "+prop+" : "+cs.getPropertyValue(prop)+"\n");
return;
}
var len = cs.length;
var list = {};
for (var i=0;i<len;i++)
{
var style = cs[i];
var value = cs.getPropertyValue(style);
//console.log(" "+style+" : "+value+"\n");
list[style] = value;
}
return list
}
copy(JSON.stringify( logComputedStyles($0) ));
// Then in a text editor
// find: ","
// replace with: ",\n"
// Repeat for the other element
// Then do side by side text comparison to see what makes them look different.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment