Reputation: 1596
I've a page like this:
<html>
<head>
<style type="text/css">
#mainDiv{
height: 100%;
}
#myDiv{
overflow: auto;
width: 400px;
}
</style>
</head>
<body>
<div id="mainDiv">
<div id="myDiv">content</div>
</div>
</body>
</html>
I wish mainDiv
was entirely contained in the screen (without scrollbars). This div contains myDiv
and myDiv
height depends on the screen height in such a way that its bottom border has a 30px margin from the screen bottom (or mainDiv
bottom).
What can I do?
Upvotes: 1
Views: 4945
Reputation: 1508
Like @Johno suggested the solution should be
#mainDiv { width: 100%; height: 100%; padding-bottom: 30px; }
#mydiv { width: 100%; height: 100%; }
but when you try this solution you get a scrollbar because the content height is bigger than that of the window.
You get this because I think that the margin is added to the height of the content (that is 100%). So the order of the rules evaluation is:
I tried to set a fixed height to the content, that is the window height minus 30 px, and I got the correct result.
Upvotes: 1
Reputation: 1959
You could try:
#mainDiv { width: 100%; height: 100%; padding-bottom: 30px; }
#mydiv { width: 100%; height: 100%; }
The padding of #mainDiv
should give the effective margin that you're hoping for on #mydiv
.
To make sure there are no scroll bars, you may need to remove padding etc from the body
too.
Upvotes: 1
Reputation: 3165
#mainDiv {
width: 100%;
height: 100%;
}
#mydiv {
width: 100%;
height: 100%;
margin-bottom: 30px;
}
HTML
<div id="mainDiv">
<div id="mydiv">content</div>
</div>
Upvotes: 1