用于隐藏 HTML 元素并保持其宽度和高度的 CSS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2306182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:16:36  来源:igfitidea点击:

CSS for hiding a HTML element, keeping its width and height?

htmlcss

提问by kat

I need a CSS snippet for hiding a HTML <div class="my">(with quite a lot of contents, including text and other divs), but still reserving space for it. Is there something better or faster than div.my{opacity:0;}?

我需要一个 CSS 片段来隐藏 HTML <div class="my">(有很多内容,包括文本和其他 div),但仍然为它保留空间。有什么比它更好或更快的div.my{opacity:0;}吗?

回答by Jamie Dixon

visibility: hidden

This will hide the element from the page but retain its place in the layout.

这将从页面隐藏元素,但保留其在布局中的位置。

回答by Parth

use document.getElementById("my").style.display = "none"; do not user visibility it only hide element but in display it remove the space acquired by element.

使用 document.getElementById("my").style.display = "none"; 不是用户可见性,它只隐藏元素,但在显示时删除元素获得的空间。