Method: 1. Set the "display:none" statement; 2. Set the "visibility:hidden" statement; 3. Set the "opacity:0" statement; 4. Set the box model attribute to 0; 5. Use "position:absolute;top:-9999px;" statement.
The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.
How to hide elements in css
display:none
Setting the display of an element to none is the most commonly used hidden element Methods.
.hide { display:none; }
After setting the element to display:none, the element will disappear completely on the page, and the space originally occupied by the element will be occupied by other elements, which means it will cause the browser to reflow and redraw. .
visibility:hidden
Setting the visibility of an element to hidden is also a commonly used method of hiding elements. The difference from display:none is that after the element disappears from the page, the space it occupies remains. will be retained, so it will only cause the browser to redraw but not reflow.
.hidden{ visibility:hidden }
visibility:hidden is suitable for scenarios where you do not want the page layout to change after the element is hidden
opacity:0
The opacity attribute I believe everyone knows that represents the element Transparency, and after setting the transparency of an element to 0, the element is also hidden in the eyes of our users. This is a method of hiding elements.
.transparent { opacity:0; }
One thing this method has in common with visibility:hidden is that the element still occupies space after being hidden, but we all know that after setting the transparency to 0, the element is just invisible, and it still exists on the page.
Set the box model attributes such as height and width to 0
This is a rather strange technique I summarized. Simply put, it is to set the margin, border, padding, height and width of the element. The attributes that affect the element box model are set to 0. If there are sub-elements or content within the element, its overflow: hidden should also be set to hide its sub-elements. This is a trick.
.hiddenBox { margin:0; border:0; padding:0; height:0; width:0; overflow:hidden; }
This method is neither practical nor may have some problems. But some page effects we usually use may be completed in this way, such as jquery's slideUp animation, which sets the element's overflow: hidden, and then continuously sets the element's height and margin-top through a timer. , margin-bottom, border-top, border-bottom, padding-top, padding-bottom are 0, thereby achieving the slideUp effect.
position: absolute, set the element to be hidden
span{ position: absolute; top: -9999px; left: -9999px; }
position: absolute, the main principle of setting the element to be hidden is to set the top and left of the element to a large enough negative number , making it invisible on the screen.
Recommended learning: "css video tutorial"
The above is the detailed content of What are the ways to hide elements in css. For more information, please follow other related articles on the PHP Chinese website!

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
