Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I collapse an empty div?

Tags:

css

I have a div that I want to use for dynamic content. When the content that fills the div is non-existent, I don't want to see it. Right now, I can see about a 5px box. Even when I remove the padding, I can still see about 1px of the box. How do I remove the box when there is no content?

#test {
border:1px dashed red;
font-size:16px;
margin:20px 0 0 0;
width:332px;
background-color:#eee;
padding:5px 0 5px 60px;
}
like image 980
Jim Avatar asked Feb 14 '11 12:02

Jim


People also ask

How do you make an empty div take up space?

Approach: The solution is to give some height (or min-height) and width (or min-width) to your HTML div. When you set a particular height and width for a div, it does not matter if it is empty or overflowed, it will only take up the space as given in the code.

Can a div be empty?

Every Website Uses Empty Divs. If you wanna use it then you can. There are no limitations.

How do you make a div go all the way down?

Set the position of div at the bottom of its container can be done using bottom, and position property. Set position value to absolute and bottom value to zero to placed a div at the bottom of container.


1 Answers

You can do in CSS:

 div#test:empty {
       display: none;
    }
like image 137
Iggy Avatar answered Sep 21 '22 22:09

Iggy