[英]how to make scrollable div below a fixed navbar
the expected outcome looks like this: not on top of the navbar, start from the bottom of the navbar 预期的结果如下所示: 不在导航栏的顶部,而是从导航栏的底部开始
instead of: start from the very top 而不是: 从头开始
I want it to be inside a DIV only. 我希望它仅在DIV中。
Here's part of my code: 这是我的代码的一部分:
<div>
<navbar style=" position: fixed;
top: 0;
left: 0;
width: 100%;
overflow: hidden;
height: 70px"/>
<div style="margin-top:80px">
I want a scroll right in this DIV.
</div>
<div>
This can be achieved with both top position or padding/margin. 这可以通过顶部位置或填充/边距来实现。 Check my working snippet: 检查我的工作片段:
body { padding: 0; margin: 0; } .navbar{ height: 60px; /* notice this value */ width: 100%; background: red; } .myScrollableDiv { position: fixed; top: 60px; /* same height as navbar */ left: 0; right: 0; bottom: 0; overflow-y: scroll; background: green; color: #fff; }
<div class="navbar"></div> <div class="myScrollableDiv"> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> <p>Test</p> </div>
On your scaffolding: 在您的脚手架上:
<div style="height: 100%"> <navbar style=" position: fixed; top: 0; left: 0; right: 0; width: 100%; height: 70px; background: red"/> <div style="margin-top:0px; margin-top: 70px; overflow-y: scroll; height: 100px"> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> I want a scroll right in this DIV. <br /> </div> <div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.