zoukankan      html  css  js  c++  java
  • html布局 左右固定,中间只适应,三种方法实现

    html布局 左右固定,中间只适应,三种方法实现

    使用自身浮动法定位

    //html
    <h3>使用自身浮动法定位</h3>
    <div id="left_self"></div>
    <div id="right_self"></div>
    <div id="center_self"></div>
    //style
    #left_self,
    #right_self {
         200px;
        height: 100px;
        background-color: #ffe6b8
    }
    #left_self {
        float: left;
    }
    #right_self {
        float: right;
    }
    #center_self {
        margin: 0 210px;
        height: 100px;
        background-color: #a0b3d6
    }
    

     

    使用margin负值法进行布局

    //html
    <h3>使用margin负值法进行布局</h3>
    <div id="wrap">
        <div id="center"></div>
    </div>
    <div id="left_margin"></div>
    <div id="right_margin"></div>
    //css
    #wrap {
         100%;
        height: 100px;
        background-color: #fff;
        float: left;
    }
    #wrap #center {
        margin: 0 210px;
        height: 100px;
        background-color: #ffe6b8;
    }
    #left_margin,
    #right_margin {
        float: left;
         200px;
        height: 100px;
        background-color: darkorange
    }
    #left_margin {
        margin-left: -100%;
        background-color: lightpink
    }
    #right_margin {
        margin-left: -200px;
    }
    

    使用flex

    //html
    <div id="box">
        <div id="left_box"></div>
        <div id="center_box"></div>
        <div id="right_box"></div>
    </div>
    //css
    #box {
         100%;
        display: flex;
        height: 100px;
    }
    #left_box,
    #right_box {
         200px;
        height: 100px;
        background-color: lightpink
    }
    #left_box {
        margin-right: 10px;
    }
    #right_box {
        margin-left: 10px;
    }
    #center_box {
        flex: 1;
        height: 100px;
        background-color: lightgreen;
    }
    

    牢固的布局跟建房子打地基一样重要

  • 相关阅读:
    解決 Android Studio 不停 Indexing 的問題(Updating Indices: Indexing paused due to batch update)
    通过某个关键字排序一个字典列表
    django cmes 后台管理
    python 处理音视频
    python 加密
    PyEngine3D
    获取单词列表出现频率最高的单词
    django 上传文件
    python之MD5加密
    切片对象的demo
  • 原文地址:https://www.cnblogs.com/yz-blog/p/7286283.html
Copyright © 2011-2022 走看看