WEB系统整体布局CSS描述

图示如下,其中Title Bar, Side Bar及Nav Bar不随滚动条滚动而上下移动:
在这里插入图片描述

详细代码与CSS如下,注释已很详尽:

<html>
    <head title='test'>
    </head>
    <body>
        <div class='container'>
            <div class='title-bar'>
                <h2>Title Bar</h2>
            </div>
            <div class='side-bar'>
                <h2>Side Bar</h2>
            </div>
            <div class='nav-bar'>
                <h2>Nav Bar</h2>
            </div>
            <div class='content'>
                test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
                test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
                test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
                test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
                test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
                test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
                test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
                test<br>test<br>test<br>test<br>test<br>test<br>test<br>test<br>
            </div>
        </div>
    </body>
    <style>
        html, body {
            height: 100%; /* 子元素高度可同屏 */
            margin: 0; /* 去除缺省margin */
        }
        .container {
            position: relative; /* 子元素使用absolute相对本元素 */
            height: 100%; /* 高度同屏 */
            width: 100%; /* 宽度同屏 */
        }
        h2 {
            color: white;
        }
        .title-bar {
            position: fixed; /* title bar不随滚动条滚动 */
            height: 64px; /* 固定高度 */
            width: 100%; /* 宽度同屏 */
            z-index: 9999; /* content向上滚动时本元素不被覆盖 */
            background-color: black;
        }
        .side-bar {
            position: fixed; /* side bar不随滚动条滚动 */
            height: calc(100% - 64px); /* 高度填满同屏除title bar的剩余部分 */
            width: 128px; /* 固定宽度 */
            top: 64px; /* 上部为title bar */
            background-color: grey;
        }
        .nav-bar {
            position: fixed; /* navigation bar不随滚动条滚动 */
            left: 128px; /* 左部为side bar */
            top: 64px; /* 上部为title bar */
            height: 64px; /* 固定宽度 */
            width: calc(100% - 128px); /* 宽度填满同屏除side bar的剩余部分 */
            z-index: 9999; /* content向上滚动时本元素不被覆盖 */
            background-color: lightgrey;
        }
        .content {
            position: absolute; /* 可随滚动条上下滚动 */
            left: 128px; /* 左部为side bar */
            top: 128px; /* 上部为title bar和navigation bar */
            width: calc(100% - 128px); /* 宽度填满同屏除side bar的剩余部分 */
            background-color: white;
        }
    </style>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值