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 p
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.
The reason it did not display is because you had position:absolute
in your style. That means that div
will be positioned independently of the other elements, and have no effect on the div
that follows. So your second div
is essentially the first div
on the screen.
Add some whitespace to your div and it will work.
<div style="height:400px; width:100%"> </div>
So I threw your code into my editor and added a black background like below...
<div style="height:400px;
width:100%;
margin:0;
padding:0;
position:absolute;
background-color: #000;">
</div>
and it showed up fine for me. I am not sure what you were expecting to see, but you can get some seemingly weird results with 'position: absolute'.
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; }
For who looking for a white space (not exactly an empty div) you can add an empty span so the div is no more considered as empty one.
Avoid using
because the default font-size
can make the div higher than you want.
div{
height:200px;
background:#ff8800;
}
<div><span></span></div>