Html 即使有背景,如何使用可见属性隐藏 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4725157/
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
How can I hide a div using visible property even it has a background
提问by Homam
I have the following div:
我有以下 div:
<div visible="false"
style="background-image:url('../Contents/Images/item-background-selected.png'); width:113px; height:58px; background-repeat: no-repeat; position: absolute;" />
<div>
It's still visible in spite of the visible
property is set to false
. but when I remove the background-image
from the style it's hidden.
尽管visible
属性设置为 ,它仍然可见false
。但是当我background-image
从样式中删除它时它被隐藏了。
How can I hide it with keeping its background?
如何在保留其背景的情况下隐藏它?
Thanks in advance.
提前致谢。
回答by Caspar Kleijne
visible="false"
is a server control property, unless the div has
是服务器控件属性,除非 div 具有
runat="server"
set, it will be ignored, since the browser/client does not know how to handle that.
设置,它将被忽略,因为浏览器/客户端不知道如何处理。
try CSS instead:
试试 CSS:
.myDivClass {
display:none; /** or: visibility:hidden; which is slightly different **/
background-image:url('../Contents/Images/item-background-selected.png');
width:113px;
height:58px;
background-repeat:
no-repeat;
position: absolute
}
回答by WraithNath
Give this a go:
试一试:
<div
style="background-image:url('../Contents/Images/item-background-selected.png'); width:113px; height:58px; background-repeat: no-repeat; position: absolute; display:none" />
<div>
note the 'display:none'
注意“显示:无”
To make it visible again you would have to remove the display:none from the div.
要使其再次可见,您必须从 div 中删除 display:none。