Reputation: 7154
display:none
will completely hide an element as if it now had a width and height of zerovisibility:hidden
on the other hand will hide an element but reserve a rectangle of the element's original width and height in the document.Is there a way through pure CSS, to hide an element such that it takes up zero height but its original width? Setting its height to zero doesnt work because I dont know to which height to set the element to once I want to show it again.
Specifically I want to achieve the following:
#top ul {take up zero height but original width}
#top:hover ul {restore original dimensions}
Edit: solved! The idea is to set height:auto
to restore the original height.
See here http://jsfiddle.net/yP59s/ for the full version or here the css:
ul {margin:0px}
#top {border:1px solid}
#top ul {height:0px;overflow:hidden}
#top:hover ul {height:auto;}
and the html:
<div id="top">
<h1>foobar</h1>
<ul>
<li>foo</li>
<li>bar</li>
</ul>
</div>
blubber
Upvotes: 25
Views: 43509
Reputation: 2382
using css
<a href="#box1">Show Box 1</a>|<a href="#box2">Show Box 2</a>|<a href="#hidebox">Hide All</a>
<div id="box1" class="box"> Contents of Box 1 </div>
<div id="box2" class="box"> Contents of Box 2 </div>
and css
.box{
border: 2px solid #ccc;
padding:20px;
margin:20px 0 0;
max-height:150px;
max-width:300px;
display:none; }
.box:target{
display:block;
}
and i found this fiddle quite a few months back, can be helpful: http://jsfiddle.net/DbXQs/
Upvotes: 1
Reputation: 11096
#top { width: 300px; height:0px; max-height:0px; }
#top:hover {height: auto; width: 300px; }
Upvotes: 9