What is the difference between display and visibility?

Source: Internet
Author: User

One, space occupy

Display:none; is completely gone, not a placeholder in the document stream, and the browser will not parse the element

Visibility:hidden, which is visually disappearing, can be understood as the effect of a transparency of 0, which occupies a position in the document flow and the browser parses the element;

using Visibility:hidden is better than display:none performance, Display:none switch display visibility, the page produces reflux (when a part of the page needs to change size, layout, display hidden, etc. The page is rebuilt, and this is the reflow. All pages need to produce a reflow when they first load, while the visibility switch does not cause reflux when it is displayed.

Second, child element inheritance

Display:none will not be the quilt element inheritance, but the parent element is not, the child elements will not show, with, Mao's Ann attached ~ ~

Visibility:hidden the quilt element inheritance, you can set the child element visibility:visible to show the child elements

opacity:0 is also inherited by the quilt element, but cannot be re-displayed by setting the child element opacity:0

Third, event binding

the Display:none element is no longer in the page, so it must not trigger the event it is bound to;

events bound by the Visibility:hidden element cannot be triggered;

The event that is bound above the opacity:0 element can be triggered.

Four, transition animation

transition is certainly not valid for display;

transition for the visibility is also invalid;

transition is valid for opacity.

Note: To set a DOM element does not appear in the browser's viewable range:

Set the width height to 0, set the transparency to 0, set the Z-index position at-100.

What is the difference between display and visibility?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.