Skip to content

Commit a0386fc

Browse files
vic-maJosh-Cena
andauthored
Mention integer vs decimal difference (#35251)
* Mention integer vs decimal difference * Update files/en-us/web/api/css_object_model/determining_the_dimensions_of_elements/index.md * Update files/en-us/web/api/css_object_model/determining_the_dimensions_of_elements/index.md --------- Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
1 parent 314a2f6 commit a0386fc

File tree

1 file changed

+1
-1
lines changed
  • files/en-us/web/api/css_object_model/determining_the_dimensions_of_elements

1 file changed

+1
-1
lines changed

files/en-us/web/api/css_object_model/determining_the_dimensions_of_elements/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ There are several properties you can look at in order to determine the width and
1010

1111
## How much room does it use up?
1212

13-
If you need to know the total amount of space an element occupies, including the width of the visible content, scrollbars (if any), padding, and border, you want to use the {{DOMxRef("HTMLElement.offsetWidth")}} and {{DOMxRef("HTMLElement.offsetHeight")}} properties. Most of the time these are the same as width and height of {{DOMxRef("Element.getBoundingClientRect()")}}, when there aren't any transforms applied to the element. In case of transforms, the `offsetWidth` and `offsetHeight` returns the element's layout width and height, while `getBoundingClientRect()` returns the rendering width and height. As an example, if the element has `width: 100px;` and `transform: scale(0.5);` the `getBoundingClientRect()` will return 50 as the width, while `offsetWidth` will return 100.
13+
If you need to know the total amount of space an element occupies, including the width of the visible content, scrollbars (if any), padding, and border, you want to use the {{DOMxRef("HTMLElement.offsetWidth")}} and {{DOMxRef("HTMLElement.offsetHeight")}} properties. Most of the time these are the same as width and height of {{DOMxRef("Element.getBoundingClientRect()")}}, when there aren't any transforms applied to the element. In case of transforms, the `offsetWidth` and `offsetHeight` returns the element's layout width and height, while `getBoundingClientRect()` returns the rendering width and height. As an example, if the element has `width: 100px;` and `transform: scale(0.5);` the `getBoundingClientRect()` will return 50 as the width, while `offsetWidth` will return 100. Another difference is that `offsetWidth` and `offsetHeight` round the values to integers, while `getBoundingClientRect()` provides more precise decimal point values.
1414

1515
![How the offsetWidth and offsetHeight properties are determined, considering padding, borders, and margin sizes](dimensions-offset.png)
1616

0 commit comments

Comments
 (0)