Screen scaling affects the size and position of page elements, so you need to handle scaling with consideration of all elements that may be affected.
1. For element tooltip, use the CSS transform property instead of the zoom property to scale. The transform keeps the element's size and position the same, but simply scales the content. For example, you could change the style of tooltip to:
.tooltip {
transform: scale(0.8);
}
Where, scale(0.8) represents 80% reduction.
2. For the dislocation of the scroll bar, JavaScript can be used to adjust the position of the scroll bar. For example, you can calculate the position ratio of the scrollbar while scaling, and then set the scrollTop property of the scrollbar. For example:
var scrollTopRatio = oldScrollTop / oldContentHeight;
var newScrollTop = newContentHeight * scrollTopRatio;
window.scrollTo(0, newScrollTop);
Where oldScrollTop and oldContentHeight are the scrollbar position and content height before scaling, while newContentHeight is the content height after scaling. By calculating the proportional relationship, you can set the new scrollbar position.
To sum up, the misalignment caused by scaling can be solved by using the transform property and JavaScript to adjust the scrollbar position. At the same time, it is recommended to write pages in relative units such as percentages or rem units rather than fixed pixel values to better accommodate different screen sizes and zoom ratios.
If the answer is helpful to you, please accept it.