可见性:隐藏的反面是可见性:可见。同样地,是否有相反的显示:没有?
当一个元素有display: none时,许多人都搞不清楚如何显示它,因为它不像使用visibility属性那么清楚。
我可以只使用visibility: hidden而不是display: none,但它不会产生相同的效果,所以我不会使用它。
可见性:隐藏的反面是可见性:可见。同样地,是否有相反的显示:没有?
当一个元素有display: none时,许多人都搞不清楚如何显示它,因为它不像使用visibility属性那么清楚。
我可以只使用visibility: hidden而不是display: none,但它不会产生相同的效果,所以我不会使用它。
当前回答
你可以使用
display: normal;
它正常工作....这是css的一个小黑客;)
其他回答
就像Paul解释的那样,没有与显示相反的文字:在HTML中没有,因为每个元素都有不同的默认显示,你也可以用类或内联样式等改变显示。
However if you use something like jQuery, their show and hide functions behave as if there was an opposite of display none. When you hide, and then show an element again, it will display in exactly the same manner it did before it was hidden. They do this by storing the old value of the display property on hiding of the element so that when you show it again it will display in the same way it did before you hid it. https://github.com/jquery/jquery/blob/740e190223d19a114d5373758127285d14d6b71e/src/css.js#L180
这意味着如果你将一个div设置为显示内联或内联块,然后隐藏它,然后再次显示它,它将再次显示为显示内联或内联块,就像之前一样
<div style="display:inline" >hello</div>
<div style="display:inline-block">hello2</div>
<div style="display:table-cell" >hello3</div>
脚本:
$('a').click(function(){
$('div').toggle();
});
请注意,即使div被隐藏(display:none)并再次显示之后,它的显示属性也将保持不变。
你可以使用
display: normal;
它正常工作....这是css的一个小黑客;)
使用display: revert
来自https://developer.mozilla.org/en-US/docs/Web/CSS/revert上的文档
revert CSS关键字将属性的级联值从其当前值恢复为如果当前样式原点未对当前元素进行任何更改,则属性将具有的值。因此,如果属性从其父继承,则将属性重置为其继承的值,或者将属性重置为用户代理的样式表建立的默认值(如果存在用户样式,则重置为用户样式)。它可以应用于任何CSS属性,包括CSS速记属性all。
它支持所有主流浏览器- https://caniuse.com/css-revert-value
这是一个来自未来的答案,在你问这个问题大约8年后。虽然仍然没有显示相反的值:没有,但继续读下去……还有更好的东西。
display属性重载得太厉害了,一点都不好笑。它至少有三个不同的功能。它控制:
外部显示类型(元素如何参与父流布局,例如块,内联) 内部显示类型(子元素的布局,例如flex, grid) 显示框(元素是否显示,例如contents, none)。
长期以来,这一直是现实,我们已经学会了忍受它,但一些姗姗来迟的改进(希望如此!)正在向我们走来。
Firefox现在支持display属性的双值语法(或多关键字值),用于分隔外部和内部显示类型。例如,block现在变成了block flow, flex变成了block flex。这并不能解决一个都没有的问题,但我认为明确的关注点分离是朝着正确方向迈出的一步。
与此同时,Chromium(85+)给了我们内容可见性属性,并大张旗鼓地宣布了它。它的目标是解决一个不同的问题——加速页面加载时间,它不呈现一个元素(及其子布局),直到它接近视口并且真正需要被看到,同时仍然可以用于“查找”搜索等。它通过给它赋值auto自动完成这个。这本身就是令人兴奋的消息,但看看它还做了什么……
The content-visibility: hidden property gives you all of the same benefits of unrendered content and cached rendering state as content-visibility: auto does off-screen. However, unlike with auto, it does not automatically start to render on-screen. This gives you more control, allowing you to hide an element's contents and later unhide them quickly. Compare it to other common ways of hiding element's contents: display: none: hides the element and destroys its rendering state. This means unhiding the element is as expensive as rendering a new element with the same contents. visibility: hidden: hides the element and keeps its rendering state. This doesn't truly remove the element from the document, as it (and it's subtree) still takes up geometric space on the page and can still be clicked on. It also updates the rendering state any time it is needed even when hidden. content-visibility: hidden, on the other hand, hides the element while preserving its rendering state, so, if there are any changes that need to happen, they only happen when the element is shown again (i.e. the content-visibility: hidden property is removed).
哇。所以这就是display:一直都不应该是——一种从布局中优雅地、完全独立于显示类型的删除元素的方法!因此,与content-visibility: hidden相反的是content-visibility: visible,但是你在auto中还有第三个非常有用的选项,它会为你做惰性渲染,加速你的初始页面加载。
唯一的坏消息是Firefox和Safari还没有采用它。但谁知道呢,当你(亲爱的开发伙伴)读到这篇文章时,情况可能已经改变了。请关注https://caniuse.com/css-content-visibility!
我使用 显示:块; 这对我很有用