zoukankan      html  css  js  c++  java
  • css flex布局

    关于flex布局的一些简单用法

    效果(下图)

    实现代码:

    <!--html-->
    <div class="wrap">
        <div class="content">这是子盒子</div>
    </div>
    
    //css
    .wrap {
        display: flex;
         300px;
        height: 300px;
        background-color: #ccc;
        justify-content: center;//子盒子位于现在的位置
        //justify-content: flex-start;子盒子位于现在的位置 的左边 
        //justify-content: flex-end;子盒子位于现在的位置 的右边  
    }
    .content {
         100px;
        height: 100px;
        line-height: 100px;
        text-align: center;
        background-color: orange;
    }

    效果(如下图)

    <!--html-->
    <div class="wrap">
        <div class="content">这是子盒子</div>
    </div>
    
    //css
    .wrap {
        display: flex;
         300px;
        height: 300px;
        background-color: #ccc;
    }
    .content {
         100px;
        height: 100px;
        line-height: 100px;
        text-align: center;
        background-color: orange;
        align-self: center;//位于上图中现在的位置
        //align-self: flex-start;位于上图中现在的位置  的上方
        //align-self: flex-end;位于上图中现在的位置  的下方
    }    
    //用于父元素
    justify-content: center | flex-start | flex-end;// 中  左   右  三个位置
    
    //用于子元素
    align-self: center | flex-start | flex-end;// 中  上   下  三个位置
    
    
    //两个属性相互结合,就可以做到很多布局

    转化成flex的元素的子元素默认是排在一行的

    flex-wrap:wrap(换行-在下方)| nowrap(换行-在上方)| none (默认-不换行)

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
        /*css*/
        .wrap{
            600px;
            height:300px;
            display:flex;
            background-color: #ccc;                     
        }
        .wrap div{
            25%;
            height: 150px;
            box-sizing: border-box;
            line-height: 150px;
            text-align: center;
            border: 1px solid blue;
        }
        </style>
    </head>
    <body>
    <div class="wrap">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
    </div>
    </body>
    </html>

    上面代码的效果图(默认不换行):

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <style>
        /*css*/
        .wrap{
            600px;
            height:300px;
            display:flex;
            background-color: #ccc;
            flex-wrap: wrap;                      
        }
        .wrap div{
            25%;
            height: 150px;
            box-sizing: border-box;
            line-height: 150px;
            text-align: center;
            border: 1px solid blue;
        }
        </style>
    </head>
    <body>
    <div class="wrap">
        <div>1</div>
        <div>2</div>
        <div>3</div>
        <div>4</div>
        <div>5</div>
    </div>
    </body>
    </html>

    上面代码的效果图(换行-在下方)

    以后有在了解的再补上

  • 相关阅读:
    在浏览器地址栏输入URL,按下回车后究竟发生了什么?
    企业内部DNS跨国配置案例
    Cobbler批量部署CentOS
    入侵检测工具之RKHunter & AIDE
    SSH服务端配置、优化加速、安全防护
    数据传输的加密过程
    mysql怎么让一个存储过程定时执行
    MYSQL中replace的用法
    eclipse 插件
    MySQL定时执行脚本(计划任务)命令实例
  • 原文地址:https://www.cnblogs.com/guojikun/p/6179283.html
Copyright © 2011-2022 走看看