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

查看:66
本文介绍了javascript - 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始终固定在上面,不随着滚动而滚动。

解决方案

看看是否是你需要的~

<!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>


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

</body>
</html>

这篇关于javascript - absolute固定标题,内容滚动问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆