我有以下HTML代码:
<html>
<body style="margin:0px; padding:0px;">
<div id="outer" style="height:100%;">
<div id="header" style="height:40px; background:blue;">Header</div>
<div id="main" style="height:100%; margin-bottom:-40px; background:red; overflow:auto;">
<p style="height:1000px">Main</p>
</div>
</div>
</body>
</html>
我只希望垂直滚动显示在主div上,当它内容超出可视区域时,似乎主div上的margin-bottom不起作用。
任何人都可以帮我解决这个问题吗?
实际上,你似乎正在解决错误的问题。如果你只是想摆脱身体本身的滚动条,请将body的样式设置为overflow:hidden
。
<html>
<body style="margin:0px; padding:0px;overflow:hidden;">
<div id="outer" style="height:100%;">
<div id="header" style="height:40px; background:blue;">Header</div>
<div id="main" style="height:100%; margin-bottom:-40px; background:red; overflow:auto;">
<p style="height:1000px">Main</p>
</div>
</div>
</body>
</html>
这应解决保证金问题,然后你要做的就是保持正确的尺寸。