"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Visibility vs. Display: Which is Better for Hiding Elements?

Visibility vs. Display: Which is Better for Hiding Elements?

Published on 2024-11-23
Browse:372

 Visibility vs. Display: Which is Better for Hiding Elements?

Implications of Hiding Elements with Visibility vs. Display

In order to simplify a web application, the behavior of menu and dialog widgets needs to be modified. Initially, the div boxes of menus were hidden using display: none; opacity: 0;. When a menu was needed, its style was changed to display: block; and then positioned using the jQuery UI position utility. Finally, its opacity was set to 1.

A new approach involves hiding div boxes with visibility: hidden and making them visible with visibility: visible. This raises a question about the implications and potential performance impact of this change.

Performance Implications

Elements with display: none; are not included in the render tree, making them more performant. In contrast, elements with visibility: hidden remain in the render tree, potentially affecting performance if a significant number are hidden at any given time.

Recommendation

While display: none; elements perform better, the impact of using visibility: hidden for a limited number of hidden div boxes is likely negligible. Therefore, the choice between the two approaches should be based on the specific functionality required. If opacity or visibility control is needed, visibility: hidden should be used. Otherwise, display: none; is preferred for better performance.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3