absolute固定标题,内容滚动问题

<div class="page">
    <header class="header-bar"></header>
    <div class="content">
        <ul><li></li>...</ul>
    </div></div>

布局差不多这样。
page的样式是absolute定位,上下左右都是0,overflow为auto。
header是absolute定位,有高度。
li有很多条,页面可滚动。

我的问题是:在header不为fixed定位的情况空下,当页面滚动的时候,header始终固定在上面,不随着滚动而滚动。


慕的地6264312
浏览 1012回答 1
1回答

不负相思意

看看是否是你需要的~<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <title>Title</title>&nbsp; &nbsp; <style>&nbsp; &nbsp; &nbsp; &nbsp; .page{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: absolute;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left:10px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top: 10px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 300px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 500px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; overflow: hidden;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; .header-bar{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; position: absolute;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; left:0px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; top:0px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 50px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #0a6ebd;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; .content{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding-top: 50px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: calc(100% - 50px);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: #ffffff;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; overflow-x: hidden;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; overflow-y: auto;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; ul{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width: 100%;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; background-color: greenyellow;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; height: 1000px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; padding: 0px;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; margin: 0px;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; </style></head><body><div class="page">&nbsp; &nbsp; <header class="header-bar"></header>&nbsp; &nbsp; <div class="content">&nbsp; &nbsp; &nbsp; &nbsp; <ul>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li></li>&nbsp; &nbsp; &nbsp; &nbsp; </ul>&nbsp; &nbsp; </div></div></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript