Reputation: 8705
HTML:
<div id="container">
<div id="topdiv" />
<div id="maindiv" />
</div>
CSS:
#topdiv {
height: 25%;
width:100%;
border:dashed;
}
#maindiv {
height: 75%;
width:100%;
border:solid;
}
Unable to stack DIVs (topdiv, maindiv) vertically one below the other. What am i doing wrong?
Upvotes: 1
Views: 10836
Reputation: 1286
If you will not close div tag, next div start from same point of first div Close Div tag
<div id="container">
<div id="topdiv"> </div>
<div id="maindiv"> </div>
</div>
Upvotes: 0
Reputation: 157414
What you are doing wrong is really basic thing, you are self closing the div
element tags, thus it renders incorrectly.
Correct Syntax
<div id="container">
<div id="topdiv"></div>
<div id="maindiv"></div>
</div>
You cannot self close the div
tags
Click here to validate your HTML documents
Upvotes: 4
Reputation: 9348
First, when you use a percentage for width/height, it's based on the parent element (width/height), which you didn't define.
Second, div
is not a self-closing tag.
HTML
<div id="container">
<div id="topdiv"></div>
<div id="maindiv"></div>
</div>
CSS
html, body, #container {
height: 100%;
}
#topdiv {
height: 25%;
width:100%;
border:dashed;
}
#maindiv {
height: 75%;
width:100%;
border:solid;
}
Working example: http://jsfiddle.net/QJC8x/
Upvotes: 0
Reputation:
html:
<div id="container">
<div id="topdiv"> </div>
<div id="maindiv"> </div>
</div>
css:
#topdiv {
height: 25%;
width:100%;
border:dashed;
}
#maindiv {
height: 75%;
width:100%;
border:solid;
}
You must close the div tags
Upvotes: 0
Reputation: 8981
try this
<div id="container">
<div id="topdiv"></div>
<div id="maindiv"></div>
</div>
CSS
html, body, #container {
height: 100%;
}
Upvotes: 1