getComputedStyle() with margin: auto
Fork this way...
HTML
<div id="box">
<div id="boat">Box with margin: 0 auto</div>
<div id="crusher">
I'm here to squash
</div>
</div>
CSS
#box {
position: relative;
width: 300px;
border: 2px solid green;
display: flex;
white-space: nowrap;
}
#boat {
width: 100px;
margin-left: auto;
border: 1px solid red;
overflow: hidden;
}
#crusher {
width: 250px;
border: 1px solid blue;
}
JavaScript
var elem = document.getElementById("boat");
var style = window.getComputedStyle(elem);
console.log("margin left:", style.marginLeft);