I am trying to learn and make a reference for myself but i can't find correct, enough, and not so confusing information. So tell me how to find the width of these..
Assume there is DOM element with 10px padding all around, border 5px all around, margin 30 px all around, and content that is too long for it so has scroll bars.
Find widths using javascript...
- upto Margin.
- upto Border.
- Inside Border Padding and plus vertical scroll bar if present.
- upto padding excluding vertical scrollbar if present.
- upto content only that is visible. (no scrollBar, padding, border, margin, extra content)
- upto content that's visible and hidden in scrollable area and with padding
- upto content that's visible and hidden in scrollable area and with out padding
Javascript as too many unintuitive catches so please make it clear once and for all.
So far I have gotten this:
- unknown
- element.offsetWidth
- unknown
- element.clientWidth
- unknown ( css width ?)
- element.scrollWidth (see below)
- unknown
only workarounds that i know are using lots of javascript to get computed values and then calculate all of these manually..but maybe there are builtin functions or better way to find things.
more Problems:
- scrollWidth includes only left padding..shouldn't it either include both or none or at least have other options that do. LINK
- box Sizing to border box changes the whole world and every question above needs to be answered again for that. For example for 5 css width property won't be true anymore.