zoukankan      html  css  js  c++  java
  • CSS3实现了左右固定中间自适应的几种方法

    1,弹性盒(flex)布局

        中间 .center 区域设置    flex-grow: 1 或者 100%

    .container {
                     100%;
                    min-height: 200px;
                    background-color: red;
                    display: flex;
                }
                .container .left {
                     200px;
                    height: 200px;
                    background-color: purple;
                }
                .container .right {
                     150px;
                    height: 200px;
                    background-color: blue;
                }
                .container .center {
                    /* flex-grow: 1; */
                     100%;
                    height: 200px;
                    background-color: orange;
                }
    
            <div class="container">
                <div class="left"></div>
                <div class="center"></div>
                <div class="right"></div>
            </div>

    2, 利用浮动(注意div排版的结构)

    .container{
                 100%;
               /* background-color: green;
                min-height: 500px; */
            }
            .left{
                 200px;
                height: 300px;
                background-color: pink;
                float: left;
            }
            .right{
                 150px;
                height: 300px;
                background-color: purple;
                float: right;
            }
            .center{
                height: 300px;
                margin-left: 200px;
                margin-right: 150px;
                background-color: blue;
            }
    
    <div class="container">
        <div class="left"></div>
        <div class="right"></div>
        <div class="center"></div>
    </div>

    3,定位 (注意div排版的结构)

    .container {
                     100%;
                    position: relative;
                }
    
                .left {
                     200px;
                    height: 300px;
                    background-color: pink;
                    position: absolute;
                    top: 0;
                    left: 0;
                    position: absolute;
                }
    
                .right {
                     150px;
                    height: 300px;
                    background-color: purple;
                    position: absolute;
                    top: 0;
                    right: 0;
                }
    
                .center {
                    height: 300px;
                    margin-left: 200px;
                    margin-right: 150px;
                    background-color: blue;
                }

    <div class="container">
    <div class="left"></div>
    <div class="right"></div>
    <div class="center"></div>
    </div>

    4, 双飞翼布局

    • left、center、right三种都设置左浮动
    • 设置center宽度为100%
    • 设置负边距,left设置负边距为100%,right设置负边距为自身宽度
    • 设置content的margin值为左右两个侧栏留出空间,margin值大小为left和right宽度
    • body {
                  min- 550px;
                  font-weight: bold;
                  font-size: 20px;
              }
      
              #container {
                  overflow: hidden;
              }
      
              #left,
              #right,
              #center {
                  float: left;
              }
      
              #center {
                   100%;
                  background: rgb(206, 201, 201);
              }
      
              #left {
                   200px;
                  margin-left: -100%;
                  background: rgba(95, 179, 235, 0.972);
              }
      
              #right {
                   150px;
                  margin-left: -150px;
                  background: rgb(231, 105, 2);
              }
      
              .content {
                  margin: 0 150px 0 200px;
              }
                      
                      <div id="container">
                  <div id="center">
                      <div class="content">#center</div>
                  </div>
                  <div id="left">#left</div>
                  <div id="right">#right</div>
              </div>
  • 相关阅读:
    某个牛人做WINDOWS系统文件详解
    常用ASP脚本程序集锦
    LINUX基础:文件安全与权限
    proftpd+mysql+quota
    apache2.0.49tomcat5.0.19jk2建立virtualHost
    URL Redirection(转) Anny
    顶级域名后缀列表(转) Anny
    \u4E00\u9FA5意义 Anny
    How to POST Form Data Using Ruby(转) Anny
    How to get rid of 'Enter password to unlock your login keyring' in Ubuntu(转) Anny
  • 原文地址:https://www.cnblogs.com/shun1015/p/12243601.html
Copyright © 2011-2022 走看看