How to make an element invisible in html

青灯夜游
Release: 2021-10-11 11:42:14
Original
9420 people have browsed it

htmlHow to set the element to be invisible: 1. Add the hidden attribute in the element tag; 2. Use the style attribute in the element tag to set the "display:none" style; 3. Use the style attribute in the element tag Set the "visibility:hidden" style.

How to make an element invisible in html

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

There are three ways to make elements invisible in html:

  • Use the hidden attribute
  • Use the style attribute to set display:none
  • Use the style attribute Set visibility: false

Obviously, there are two ways to make an element invisible:

  • The element is completely invisible, and the element does not occupy space and seems to disappear
  • The element is invisible, but still occupies the original space, as if invisible

Use the hidden attribute

<div hidden>hello</div>
Copy after login

The effect of using the hidden attribute is that when rendering the DOM, the display attribute of the element will be automatically changed to none. Note that the only use of the hidden attribute is here: just change the display to none the first time you add the hidden attribute. In the future, even if the display attribute changes to block, the hidden attribute will still be there.

It can be seen that the effects of hidden and display=none are the same. But it is not as direct and fundamental as display. Therefore, do not use the hidden attribute in the future and directly access the display attribute in style.

Use the style attribute to set display:none

The display=none in style can make an element disappear completely without a trace. Takes up space.

<div style="display:none">hello</div>
Copy after login

Use the style attribute to set visibility=hidden

When visibility=hidden in style, the element seems to be invisible, but it still occupies the original Space.

<div style="visibility:hidden">hello</div>
Copy after login

Recommended tutorial: "html video tutorial"

The above is the detailed content of How to make an element invisible in html. For more information, please follow other related articles on the PHP Chinese website!

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