可见性:隐藏的反面是可见性:可见。同样地,是否有相反的显示:没有?
当一个元素有display: none时,许多人都搞不清楚如何显示它,因为它不像使用visibility属性那么清楚。
我可以只使用visibility: hidden而不是display: none,但它不会产生相同的效果,所以我不会使用它。
可见性:隐藏的反面是可见性:可见。同样地,是否有相反的显示:没有?
当一个元素有display: none时,许多人都搞不清楚如何显示它,因为它不像使用visibility属性那么清楚。
我可以只使用visibility: hidden而不是display: none,但它不会产生相同的效果,所以我不会使用它。
当前回答
Display: none不像visibility:hidden那样有字面上的相反含义。
visibility属性决定一个元素是否可见。因此,它有两种状态(可见和隐藏),它们彼此相反。
然而,display属性决定了元素将遵循什么布局规则。对于元素如何在CSS中布局,有几种不同的规则,因此有几种不同的值(块,内联,内联块等-请参阅这里的文档)。
Display:none从页面布局中完全删除一个元素,就好像它不存在一样。
所有其他用于显示的值都使元素成为页面的一部分,因此在某种意义上,它们都与显示相反:none。
但是没有一个值是与显示直接相反的:没有——就像没有一种发型是与“秃头”相反的一样。
其他回答
恢复到原来的状态put:
display=""
我使用 显示:块; 这对我很有用
在打印机友好的样式表的情况下,我使用以下:
/* screen style */
.print_only { display: none; }
/* print stylesheet */
div.print_only { display: block; }
span.print_only { display: inline; }
.no_print { display: none; }
I used this when I needed to print a form containing values and the input fields were difficult to print. So I added the values wrapped in a span.print_only tag (div.print_only was used elsewhere) and then applied the .no_print class to the input fields. So on-screen you would see the input fields and when printed, only the values. If you wanted to get fancy you could use JS to update the values in the span tags when the fields were updated but that wasn't necessary in my case. Perhaps not the the most elegant solution but it worked for me!
你可以使用这个display:block;并同时添加overflow:hidden;
就像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)并再次显示之后,它的显示属性也将保持不变。