zoukankan      html  css  js  c++  java
  • CSS实现三栏布局,左右宽度固定,中间宽度自适应

    假设高度一定,请写出三栏布局,左右宽度300px,中间自适应。
    首先要写好整个页面的布局:

        <style>
            html * {            padding: 0;            margin: 0;        }
    
            .layout {            margin-top: 20px;        }
    
            .layout article div {            min-height: 100px;        }
        </style>123456789101112131415

    1.浮动的解决方案

    <!-- 浮动布局解决方案 -->
        <section class="layout float">
            <style>
                .layout.float .left {                float: left;                 300px;                background: red;            }
    
                .layout.float .right {                float: right;                 300px;                background: blue;            }
    
                .layout.float .center {                background: yellow;            }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="right"></div>
                <div class="center">
                    <h1>浮动解决方案</h1>
                    <p>1.这是布局的中间部分</p>
                    <p>2.这是布局的中间部分</p>
                </div>
            </article>
        </section>123456789101112131415161718192021222324252627282930

    2.绝对定位的解决方案

    <!-- 绝对定位的解决方案 -->
        <section class="layout absolute">
            <style>
                .layout.absolute .left-center-right>div {                position: absolute;            }
    
                .layout.absolute .left {                left: 0;                 300px;                background: red;            }
    
                .layout.absolute .center {                left: 300px;                right: 300px;                background: yellow;            }
    
                .layout.absolute .right {                right: 0;                 300px;                background: blue;            }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>绝对定位的解决方案</h1>
                    <p>1.这是布局的中间部分</p>
                    <p>2.这是布局的中间部分</p>
                </div>
                <div class="right"></div>
            </article>
        </section>123456789101112131415161718192021222324252627282930313233343536

    3.flexbox的解决方案

    <!-- flexbox解决方案 -->
        <section class="layout flexbox">
            <style>
                .layout.flexbox {                margin-top: 140px;            }
    
                .layout.flexbox .left-center-right {                display: flex;            }
    
                .layout.flexbox .left {                 300px;                background: red;            }
    
                .layout.flexbox .center {                flex: 1;                background: yellow;            }
    
                .layout.flexbox .right {                 300px;                background: blue;            }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>flexbox的解决方案</h1>
                    <p>1.这是布局的中间部分</p>
                    <p>2.这是布局的中间部分</p>
                </div>
                <div class="right"></div>
            </article>
        </section>12345678910111213141516171819202122232425262728293031323334353637

    4.表格布局的解决方案

    <!-- 表格布局的解决方案 -->
        <section class="layout table">
            <style>
                .layout.table .left-center-right {                 100%;                display: table;                height: 100px;            }
    
                .layout.table .left-center-right>div {                display: table-cell;            }
    
                .layout.table .left {                 300px;                background: red;            }
    
                .layout.table .center {                background: yellow;            }
    
                .layout.table .right {                 300px;                background: blue;            }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>表格布局的解决方案</h1>
                    <p>1.这是布局的中间部分</p>
                    <p>2.这是布局的中间部分</p>
                </div>
                <div class="right"></div>
            </article>
        </section>1234567891011121314151617181920212223242526272829303132333435363738

    5.网格布局的解决方案

    <!-- 网格布局的解决方案     -->
        <section class="layout grid">
            <style>
                .layout.grid .left-center-right {                display: grid;                 100%;                grid-template-rows: 100px;                grid-template-columns: 300px auto 300px;            }
    
                .layout.grid .left {                background: red;            }
    
                .layout.grid .center {                background: yellow;            }
    
                .layout.grid .right {                background: blue;            }
            </style>
            <article class="left-center-right">
                <div class="left"></div>
                <div class="center">
                    <h1>网格布局的解决方案</h1>
                    <p>1.这是布局的中间部分</p>
                    <p>2.这是布局的中间部分</p>
                </div>
                <div class="right"></div>
            </article>
        </section>123456789101112131415161718192021222324252627282930313233

    效果图:
    这里写图片描述

     本文转载自:https://www.juchengvi.com/looknews/145
  • 相关阅读:
    【Hadoop 分布式部署 五:分布式部署之分发、基本测试及监控】
    【Hadoop 分布式部署 四:配置Hadoop 2.x 中主节点(NN和RM)到从节点的SSH无密码登录】
    【Hadoop 分布式部署 三:基于Hadoop 2.x 伪分布式部署进行修改配置文件】
    【Hadoop 分布式部署 二:分布式环境预备工作(主机名 IP地址等设置)】
    【Hadoop 分布式部署 一 :分布式部署准备虚拟机 】
    Java基础 【类之间的关系】
    Java基础 【自动装箱和拆箱、面试题】
    java算法 第七届 蓝桥杯B组(题+答案) 3.凑算式
    java算法 第七届 蓝桥杯B组(题+答案) 2.生日蜡烛
    java算法 第七届 蓝桥杯B组(题+答案) 1.煤球数目
  • 原文地址:https://www.cnblogs.com/jucheng/p/13743222.html
Copyright © 2011-2022 走看看