CSS布局实现

图片描述

如何实现图片中的布局,顶部,底部固定,中间内容包括导航栏和内容列表,并且宽度为1200px。左侧导航也为固定,请教大家如何实现

阅读 3.9k
6 个回答

上下用display:fixed 定位,中间用一个div包起来,margin:90px auto;width:1200px;
90px为你上下定位的元素的高度

要固定的话是position:fixed,头部再包一个div,让它在头部居中,下面也是差不多的。

<header><div class="fixed">我是头部</div></header>
<main><div class="sidebar fixed">我是侧边栏</div>我是主体内容</main>
<footer><div class="fixed">我是底部</div></footer>

fixed = position: fixed;

大致就是上面这样...供参考...

头部和尾部用position:fixed 定位,中间用写,margin:90px auto;width:1200px;就可以了。

首先你所谓的固定死,滚动时依然位置不变吗?如果是那就header和footer都fixed;中间中正常
<div class="head"></div>//position:fixed
<div class="content"> //最好给个min-height不然没有内容是就尴尬了
<div class="left-mod"></div>
<div class="mid-mod"></div>
</div>
<div class="foot"></div> //position:fixed
如果没有需求说滚动是头部底部位置不变,那就不需要fixed,正常布局就行

<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta charset="utf-8">
    <meta name="author"content="zhengfuxing">
    <title></title>
    <style>
        body{
            margin: 0;
            text-align:center;
        }
        .header{
            position: fixed;
            top: 0;
            width: 100%;
            background: pink;
            height: 100px;
            
        }
         .footer{
            position: fixed;
            width: 100%;
            bottom: 0;
            height: 100px;
            background:lightgreen;
            
        }
        .content{
            height: 500px;
            width: 100%;
            background:#fff;
            margin-top: 100px;

        }
        .content-body{
            width: 1200px;
            background: rosybrown;
            margin: 0 auto;
            height: 500px;
        }
        .left-menu{
            position: fixed;
            width: 150px;
            background:palegoldenrod;
            height: 500px;
            top: 100px;
        }
        .right-list{
            width: 1050px;
            margin-left: 150px;
            background: wheat;
            height: 500px;
        }
         
    </style>
</head>
<body>
    <div class="header">我是头部</div>
    <div class="content">
        <div class="content-body">
            <div class="left-menu">我是导航栏</div>
            <div class="right-list">我是内容列表</div>

        </div>
    </div>
    <div class="footer">我是底部</div>
    
</body>
</html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题