zoukankan      html  css  js  c++  java
  • css常见布局之三列布局--双飞翼布局和圣杯布局

    首先两者都是两边宽度固定,中间宽度自适应,并且中间盒子(主题内容)放在最前面,以便优先渲染。

    实现方案:都使用浮动来实现。

    圣杯布局实现如下:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>圣杯布局</title>
        <style>
            .box{
                padding: 0 100px;
                height: 400px;
            }
            .center,
            .left,
            .right{
                float: left;
                height: 100%;
            }
            .left,
            .right{
                position: relative;
            }
            .center{
                 100%;
                background: #333;
            }
            .left{
                 100px;
                background: #f8f8f8;
                margin-left: -100%; /*为了使元素移到上一行,margin-left设置百分比是相对于父元素宽度的,这个宽度是不包括padding在内*/
                left: -100px;
            }
            .right{
                 100px;
                background: #ccc;
                margin-left: -100px;
                right: -100px;
            }
        </style>
    </head>
    <body>
        <div class="box">
            <div class="center"></div>
            <div class="left"></div>
            <div class="right"></div>
        </div>
    </body>
    </html>
     
     flex实现圣杯布局:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    * {
    margin: 0;
    padding: 0;
    }
    html,
    body {
    height: 100%;
    overflow: hidden;
    display: flex;
    /* 改变主轴的排列方式 */
    flex-direction: column;
    justify-content: space-between;
    text-align: center;
    font-size: 25px;
    }
    .footer,
    .header {
    height: 88px;
    background: #c33;
    text-align: center;
    line-height: 88px;
    font-size: 30px;
    }
    .center {
    flex: 1;
    background: #ccc;
    display: flex;
    }
    .center>.left,.center>.right {
    200px;
    height: 100%;
    background: yellow;
    }
    .center>.content {
    flex: 1;
    background: pink;
    }
    </style>
    </head>
    <body>
    <div class="header">header</div>
    <div class="center">
    <div class="left">left</div>
    <div class="content">content</div>
    <div class="right">right</div>
    </div>
    <div class="footer">footer</div>
    </body>
    </html>
     
    双飞翼布局实现如下:
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>双飞翼布局</title>
        <style>
            .box{
                height: 400px;
                overflow: hidden;
            }
            .main-box,
            .left,
            .right{
                float: left;
                height: 100%;
            }
            .center{
                margin-left: 100px;
                margin-right: 100px;
            }
            .main-box{
                 100%;
                background: #333;
            }
            .left{
                 100px;
                background: #f8f8f8;
                margin-left: -100%;
            }
            .right{
                 100px;
                background: #ccc;
                margin-left: -100px;
            }
        </style>
    </head>
    <body>
        <div class="box">
            <div class="main-box"><div class="center"></div></div>  
            <div class="left"></div>
            <div class="right"></div>
        </div>
    </body>
    </html>
  • 相关阅读:
    一个2013届毕业生(踏上IT行业)的迷茫(2)
    一个2013届毕业生(踏上IT行业)的迷茫(1)
    Java 开源博客——B3log Solo 0.6.5 正式版发布了!
    Java 开源博客——B3log Solo 0.6.5 正式版发布了!
    在CSDN博客中添加量子恒道统计功能的做法
    Struts2——(8)struts2中文件的上传
    Struts2——(7)拦截器组件
    让富文本编辑器支持复制doc中多张图片直接粘贴上传
    ASP net 上传整个文件夹
    js文件夹上传
  • 原文地址:https://www.cnblogs.com/znyu/p/10843696.html
Copyright © 2011-2022 走看看