Home > Web Front-end > JS Tutorial > body text

Example explanation of the difference between style.display and style.visibility in JS_javascript skills

WBOY
Release: 2016-05-16 17:39:20
Original
1275 people have browsed it

In JS, you can control whether an element is displayed by setting the style.display or style.visibility attributes. When style.display=block and style.visibility=visible, the element is displayed. When style.display=none and style.visibility= When hidden, the element is hidden. The biggest difference between them is that when hidden by style.display=none, the element does not occupy its original position and is separated from the document flow, and subsequent elements fill its position. When hidden through style.visibility=hidden, the element still occupies the original position, but is hidden.

The following example illustrates this difference: In this example, divContent1 and divContent2 are hidden using style.display=none. At this time, the following divs will move upward and occupy the already hidden divs. space. divContent3 and divContent4 use style.visibility=hidden to hide them, but they still occupy the original space after being hidden.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!