As for Javascript in the browser, the window.getComputedStyle() method of the window.getComputedStyle() should window.getComputedStyle() last used CSS property values โโapplied to the element. According to the MDN documentation , this means "after all the calculations have been completed."
However, it seems that โall settlementsโ do not include margin reduction. In Firefox and Chrome (at least), the getComputedStyle().marginBottom returns the calculated value before any getComputedStyle().marginBottom fields are getComputedStyle().marginBottom .
For example, consider the following element:
<div style="margin: 10px 0 15px 0"></div>
Its top and bottom margins will be collapsed because (approximately) its content height is zero (see W3C CSS2 Recommendation ). CSSOM methods will return these values:
getComputedStyle().marginTop โ 10px getComputedStyle().marginBottom โ 15px getBoundingClientRect().top โ {top of margin box} + marginTop getBoundingClientRect().bottom โ idem top
But due to the narrowing of the fields, the layout shows max(0, marginBottom - marginTop) before the bounding client rectangle and max(0, marginBottom - marginTop) after, i.e. max(0, marginBottom - marginTop) .
Why getComputedStyle().marginBottom directly return 5px, the actual value used is โafter all calculations have been completedโ, instead of the specified 15px? Is this a W3C recommended behavior? (I did not see anything about this in the w3.org docs.)
Is this a bug or a feature?
source share