Notice I am measuring from the outside border of the red
As previously mentioned If I was to change the blue
The image of the browser view shown below clarifies the new measurements returned from offsetLeft and offsetTop when the offsetParent is the blue
Notes
Many of the browsers break the outside border to inside border measurement when the offsetParent is the
and the or element has a visible margin, padding, or border value.Using the getBoundingClientRect() method we could have the status regarding an elements exterior edging edges as the painted on the browser viewport in line with the fresh new better and kept edge of the latest viewport. It means the leftover and you will correct edge was measured about external edging edge of a component left edge of the viewport. In addition to top and you may base edges is actually mentioned regarding exterior edging side of a feature to reach the top side of this new viewport.
In the code below I create a 50px X 50px
The image below suggests the web browser rendered look at these password which includes added dimension signs showing exactly how getBoudingClientRect() are computed. Read More 5.step three Getting a section best, correct, base and you will kept border border offset relative to new viewport using getBoundingClientRect()