zoukankan      html  css  js  c++  java
  • CSS 实现两边固定中间宽度自适应效果

    效果如图

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Document</title>
    </head>
    
    <style>
      /* .main {
         600px;
        margin: auto;
      } */
      .left {
        width: 100px;
        height: 20px;
        background-color: aquamarine;
      }
      .center {
        height: 20px;
        background-color: thistle;
      }
      .right {
        width: 100px;
        height: 20px;
        background-color: yellow;
      }
      .flex {
        display: flex;
      }
      .grow-box .center {
        flex-grow: 1;
      }
      /*shrink*/
      .shrink-box div {
        flex-shrink: 0;
      }
      .shrink-box .center {
        width: 100%;
        flex-shrink: 2;
      }
      /*calc*/
      .calc-box {
        display: flex;
      }
      .calc-box .center {
        width: calc(100% - 200px);
      }
      /*position*/
      .position-box {
        justify-content: space-between;
        position: relative;
      }
      .position-box .center {
        position: absolute;
        left: 100px;
        right: 100px;
      }
      /*float*/
      .float-box { 
        clear: both;
        overflow: hidden;
      }
      .float-box .left {
        float: left;
      }
      .float-box .right {
        float: right;
      }
    </style>
    <body>
      <div class="main">
        <h3>flex-grow方法(给中间元素设置 flex-grow: 1)</h3>
        <div class="flex grow-box">
          <div class="left"></div>
          <div class="center"></div>
          <div class="right"></div>
        </div>
      </div>
      <div class="main">
        <h3>flex-shrink方法(给中间元素设置flex-shrink: 2,left 和 right 设置 flex-shrink: 0)</h3>
        <div class="flex shrink-box">
          <div class="left"></div>
          <div class="center"></div>
          <div class="right"></div>
        </div>
      </div>
      <div class="main">
        <h3>flex + calc方法 ( calc(100% - 200px);)</h3>
        <div class="flex calc-box">
          <div class="left"></div>
          <div class="center"></div>
          <div class="right"></div>
        </div>
      </div>
      <div class="main">
        <h3>万能定位法</h3>
        <div class="flex position-box">
          <div class="left"></div>
          <div class="center"></div>
          <div class="right"></div>
        </div>
      </div>
      <div class="main">
        <h3>float 方法(*cneter放到最下面)</h3>
        <div class="float-box">
          <div class="left"></div>
          <div class="right"></div>
          <div class="center"></div>
        </div>
      </div>
    </body>
    </html>
  • 相关阅读:
    我的又一个web2.0作品
    AjaxPro使用注意事项与返回数据库中数据时2.0和3.5/4.0的区别(我的心得)
    AjaxPro入门使用方法
    SQLHelper的简单应用,高手绕道,写出最近用的一个类,仅供初学者参考
    Notepad++插件NPPExec编译运行C++、JAVA和Python代码
    在Ubuntu 18.04 LTS上搭建SS并启用BBR
    Linux 目录和文件管理
    chap06
    三层交换机的VLAN划分
    传输协议
  • 原文地址:https://www.cnblogs.com/fczbk/p/13820173.html
Copyright © 2011-2022 走看看