Is there a deviation in the value of JS offsetWidth?

problem arises: I use js to dynamically set the width of a box, the parent box is width:100%, but js always deviates from the actual value when using offsetWidth to get the value of the parent box. As shown in figure

clipboard.png

May.09,2021

I have the same situation. I measured the width of the scroll bar and found that the 17 pixels with deviation was the width of the scroll bar

.
Menu