getComputedStyle() with margin: auto

Fork this way...

by mpetrovich

HTML

<div id="box">
    <div id="boat">Box with margin: 0 auto</div>
</div>

CSS

#box {
    position: relative;
    width: 300px;
    border: 2px solid green;
}

#boat {
    width: 100px;
    margin: 0 auto;
    border: 1px solid red;
}

JavaScript

var elem = document.getElementById("boat");
var style = window.getComputedStyle(elem);

console.log("margin left:", style.marginLeft);