How to hide elements in css without taking up space

青灯夜游
Release: 2022-06-01 19:34:40
Original
5103 people have browsed it

Two methods: 1. Using the display attribute, just add the "display:none;" style to the element. 2. Use the position and top attributes to set the absolute positioning of the element to hide the element. Just add the "position:absolute;top:-9999px;" style to the element.

How to hide elements in css without taking up space

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

Two ways to hide elements in css without taking up space

Method 1: Use the display attribute

Just set thedisplay:none;style to the element

     
正常显示元素
隐藏元素
正常显示元素
Copy after login

How to hide elements in css without taking up space

##Instructions:

display: nonecan hide the element without occupying space, so dynamically changing this attribute will cause rearrangement (change the page layout), which can be understood as deleting the element from the page; it will not be inherited by descendants, but His descendants will not be shown, after all, they are all hidden together.

Method 2: Using position and top attributes

Just add

position: absolute;top: -9999px;style to the element

     
正常显示元素
隐藏元素
正常显示元素
Copy after login

How to hide elements in css without taking up space

Explanation:

This method is to take the element out of the document flow (without taking up space) by deciding the positioning, and then set the top of the element to A large enough negative number to make it invisible on the screen.

The above is the detailed content of How to hide elements in css without taking up space. 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
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!