javascript - absolute固定标题,内容滚动问题
阿神
阿神 2017-04-11 12:46:31
[JavaScript讨论组]

  • ...

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

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

阿神
阿神

闭关修行中......

全部回复(3)
大家讲道理

看看是否是你需要的~

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .page{
            position: absolute;
            left:10px;
            top: 10px;

            width: 300px;
            height: 500px;
            overflow: hidden;
        }
        .header-bar{
            position: absolute;
            left:0px;
            top:0px;
            width: 100%;
            height: 50px;
            background-color: #0a6ebd;
        }
        .content{
            padding-top: 50px;
            width: 100%;
            height: calc(100% - 50px);
            background-color: #ffffff;
            overflow-x: hidden;
            overflow-y: auto;
        }

        ul{
            width: 100%;
            background-color: greenyellow;
            height: 1000px;
            padding: 0px;
            margin: 0px;
        }
    </style>
</head>
<body>


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

</body>
</html>
高洛峰

content设置高度,overflow-y:scroll,header static定位。

PHPz

为什么不直接设content的overflow呢?page里面还有什么内容吗

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号