CSS“显示:无;"财产 [英] CSS "Display: none;" property

查看:29
本文介绍了CSS“显示:无;"财产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我为特定的 div 提供了 display:none; 属性.所以,我的问题是页面加载时是否加载 div?

If I provide a display:none; property to a particular div. So, My Question is that is that div load when a page loads?

推荐答案

简短回答:是的,它会加载.

更长、更好的答案:是的,HTML 文件中的所有元素都将加载并成为 DOM 的一部分,这意味着它们可以使用 JavaScript 定位,无论是否显示.如果您添加任何带有 display: none 的元素,该元素将被加载到页面上,但 display: none 属性会告诉浏览器隐藏它(用户根本无法与之交互).然后你可以展示它,或者用它做任何你想做的事情.

Longer, better answer: Yeah, all elements that are in the HTML file will load and be part of the DOM, which means that they can then be targeted using JavaScript, displayed or not. If you add any element with display: none, the element will be loaded on the page but the display: none property will tell the browser to hide it (users can't interact with it at all). You can then show it, or do whatever you want with it.

根据 MDN 显示:无将:

关闭元素的显示(对布局没有影响);全部后代元素的显示也被关闭.文件呈现为好像该元素不存在.

Turns off the display of an element (it has no effect on layout); all descendant elements also have their display turned off. The document is rendered as though the element did not exist.

要渲染元素框的尺寸,但要使其内容不可见,请参阅可见性属性.

To render an element box's dimensions, yet have its contents be invisible, see the visibility property.

这样做的好处是,例如,您可以添加仅在用户单击按钮时显示的叠加层.然后你添加一些 JavaScript 函数,这样当用户点击它时,覆盖就会显示出来.魔法!

The advantage of this is that you can, for example, add an overlay that will show only when the user clicks on a button. Then you add some JavaScript function so that when the user clicks on it, the overlay will show. Magic!

您可以在此处

这篇关于CSS“显示:无;"财产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆