三列布局

一. 三列布局的要求

  1. 两边固定,中间自适应
  2. 中间列要完整显示
  3. 中间列要优先加载

二. 三列布局的实现

  1. 圣杯布局
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0
        }

        body {
            min-width: 600px;
        }

        .clearfix::before,
        .clearfix::after {
            content: " ";
            display: table;
            clear: both;
        }

        #header,
        #footer {
            height: 20px;
            text-align: center;
            border: 1px solid deeppink;
            background-color: gray;
        }

        #content {
            overflow: hidden;
            padding: 0 200px;
        }

        #contenr .middle,
        #content .left,
        #content .right {
            padding-bottom: 10000px;
            margin-bottom: -10000px;
        }

        #content .middle {
            float: left;
            width: 100%;
            background-color: pink;
        }

        #content .left {
            float: left;
            width: 200px;
            background-color: yellow;
            margin-left: -100%;
            position: relative;
            left: -200px
        }

        #content .right {
            float: left;
            width: 200px;
            background-color: yellow;
            margin-left: -200px;
            position: relative;
            right: -200px;
        }
    </style>
</head>

<body>
    <div id="header">header</div>
    <div id="content" class="clearfix">
        <div class="middle">
            <h4>middle</h4>
            <h4>middle</h4>
            <h4>middle</h4>
            <h4>middle</h4>
            <h4>middle</h4>
            <h4>middle</h4>
        </div>
        <div class="left">left</div>
        <div class="right">right</div>
    </div>
    <div id="footer">footer</div>
</body>

</html>
  1. 双飞翼布局
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0
        }

        body {
            min-width: 600px;
        }

        .clearfix::before,
        .clearfix::after {
            content: " ";
            display: table;
            clear: both;
        }

        #header,
        #footer {
            height: 20px;
            text-align: center;
            border: 1px solid deeppink;
            background-color: gray;
        }

        #content {
            overflow: hidden;
        }
        
        #content .middle .m_inner{
            padding: 0 200px;
        }

        #contenr .middle,
        #content .left,
        #content .right {
            padding-bottom: 10000px;
            margin-bottom: -10000px;
        }

        #content .middle {
            float: left;
            width: 100%;
            background-color: pink;
        }

        #content .left {
            float: left;
            width: 200px;
            background-color: yellow;
            margin-left: -100%;
        }

        #content .right {
            float: left;
            width: 200px;
            background-color: yellow;
            margin-left: -200px;
        }
    </style>
</head>

<body>
    <div id="header">header</div>
    <div id="content" class="clearfix">
        <div class="middle">
            <div class="m_inner">
                <h4>middle</h4>
                <h4>middle</h4>
                <h4>middle</h4>
                <h4>middle</h4>
                <h4>middle</h4>
                <h4>middle</h4>
            </div>
        </div>
        <div class="left">left</div>
        <div class="right">right</div>
    </div>
    <div id="footer">footer</div>
</body>

</html>

三. 两种实现方式的异同

  1. 两种布局方式都是把主列放在文档流的最前面,使主列优先加载
  2. 两种布局方式在实现上有相同之处,都是让三列浮动,通过外边距为负形成三列布局
  3. 两种布局方式的不同之处在于如何处理中间主列的位置
    (1) 圣杯布局是利用父容器的左、右内边距+两个从列相对定位
    (2) 双飞翼布局是把主列嵌套在一个新的父级块中利用主列的左、右外边距进行布局调整
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值