Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty div (with style: height) will not display

Tags:

html

css

Incredibly simple piece of HTML - but not displaying how I would expect.

I'm trying to create an empty div that displays as whitespace on the top of the page, with style="height: 400px;"

Even though I have specified a height, my empty div will not display. What am I missing here?

UPDATE: my main question is: Why does an empty div not display even if it has a height set? Or, what are the basic style rules needed to display an empty div?

Full code:

<html> <head><title>Site Name</title> </head> <body> <div style="height:400px; width:100%; margin:0; padding:0; position:absolute;"></div> <div style="width: 50%; margin: auto;"> <img src="logo.gif"></div>   <div style="width: 50%; margin: auto;"></div>  </body> </html> 
like image 647
azochz Avatar asked Sep 25 '13 01:09

azochz


People also ask

Why does my div have no height?

The reason why the height or the containers is 0 is because you are floating all the content inside them and floated elements don't expand the height (or width) of their parents.

Why is height property not working CSS?

If the height of the containing block is not specified explicitly and this element is not absolutely positioned, the value computes to 'auto'. The height depends on the values of other properties. Note that min-height and max-height are not acceptable. It must be the height property.


2 Answers

If you just want to add white space try this

<div style="height:400px; width:100%; clear:both;"></div> 

FIDDLE

or you could just add padding to the body like body { padding-top: 400px; }

like image 195
mdesdev Avatar answered Oct 03 '22 23:10

mdesdev


The css style you are looking for is min-height: 20px; By default a div without content will have a height of 0 due to the auto setting being the default which sizes itself to fit content.

enter image description here

enter image description here

like image 40
Dmitri Larionov Avatar answered Oct 04 '22 00:10

Dmitri Larionov