Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 83094|回复: 0

display:flex不兼容Android、Safari低版本的解决方案 【flex布局】

[复制链接]
  • TA的每日心情
    奋斗
    2024-4-6 11:05
  • 签到天数: 748 天

    [LV.9]以坛为家II

    2034

    主题

    2092

    帖子

    70万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    705612
    发表于 2021-4-5 15:00:46 | 显示全部楼层 |阅读模式

     

     

     

     

     

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>flexbox布局</title>
        <style>
        div {
            border: 1px solid #000;
            overflow: hidden;
        }
        div.flex-h:before, div.flex-v:before {
            content: "before";
        }
        div.flex-h:after, div.flex-v:after {
            content: "after";
        }
        .w60 {
            width: 60px;
        }
        .w150 {
            width: 150px;
        }
        .w200 {
            width: 200px;
        }
        .h30 {
            height: 30px;
        }
        .h50 {
            height: 50px;
        }
        /* 父元素-flex容器 */
        .flex {
            display: box;              /* OLD - Android 4.4- */
    
            display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
            display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
            display: -ms-flexbox;      /* TWEENER - IE 10 */
            display: -webkit-flex;     /* NEW - Chrome */
            display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
        }
        /* 子元素-平均分栏 */
        .flex1 {
            -webkit-box-flex: 1;      /* OLD - iOS 6-, Safari 3.1-6 */
            -moz-box-flex: 1;         /* OLD - Firefox 19- */
            width: 20%;               /* For old syntax, otherwise collapses. */
            -webkit-flex: 1;          /* Chrome */
            -ms-flex: 1;              /* IE 10 */
            flex: 1;                  /* NEW, Spec - Opera 12.1, Firefox 20+ */
        }
        /* 父元素-横向排列(主轴) */
        .flex-h {
            display: box;              /* OLD - Android 4.4- */
            
            display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
            display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
            display: -ms-flexbox;      /* TWEENER - IE 10 */
            display: -webkit-flex;     /* NEW - Chrome */
            display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
    
    
            /* 09版 */
            -webkit-box-orient: horizontal;
            /* 12版 */
            -webkit-flex-direction: row;
            -moz-flex-direction: row;
            -ms-flex-direction: row;
            -o-flex-direction: row;
            flex-direction: row;
        }
        /* 父元素-横向换行 */
        .flex-hw {
            /* 09版 */
            -webkit-box-lines: multiple;
            /* 12版 */
            -webkit-flex-wrap: wrap;
            -moz-flex-wrap: wrap;
            -ms-flex-wrap: wrap;
            -o-flex-wrap: wrap;
            flex-wrap: wrap;
        }
        /* 父元素-水平居中(主轴是横向才生效) */
        .flex-hc {
            /* 09版 */
            -webkit-box-pack: center;
            /* 12版 */
            -webkit-justify-content: center;
            -moz-justify-content: center;
            -ms-justify-content: center;
            -o-justify-content: center;
            justify-content: center;
            /* 其它取值如下:
                align-items     主轴原点方向对齐
                flex-end        主轴延伸方向对齐
                space-between   等间距排列,首尾不留白
                space-around    等间距排列,首尾留白
             */
        }
        /* 父元素-纵向排列(主轴) */
        .flex-v {
            display: box;              /* OLD - Android 4.4- */
            
            display: -webkit-box;      /* OLD - iOS 6-, Safari 3.1-6 */
            display: -moz-box;         /* OLD - Firefox 19- (buggy but mostly works) */
            display: -ms-flexbox;      /* TWEENER - IE 10 */
            display: -webkit-flex;     /* NEW - Chrome */
            display: flex;             /* NEW, Spec - Opera 12.1, Firefox 20+ */
    
    
            /* 09版 */
            -webkit-box-orient: vertical;
            /* 12版 */
            -webkit-flex-direction: column;
            -moz-flex-direction: column;
            -ms-flex-direction: column;
            -o-flex-direction: column;
            flex-direction: column;
        }
        /* 父元素-纵向换行 */
        .flex-vw {
            /* 09版 */
            -webkit-box-lines: multiple;
            /* 12版 */
            -webkit-flex-wrap: wrap;
            -moz-flex-wrap: wrap;
            -ms-flex-wrap: wrap;
            -o-flex-wrap: wrap;
            flex-wrap: wrap;
        }
        /* 父元素-竖直居中(主轴是横向才生效) */
        .flex-vc {
            /* 09版 */
            -webkit-box-align: center;
            /* 12版 */
            -webkit-align-items: center;
            -moz-align-items: center;
            -ms-align-items: center;
            -o-align-items: center;
            align-items: center;
        }
    
        .flex-1 {
            -webkit-box-ordinal-group: 1;   /* OLD - iOS 6-, Safari 3.1-6 */
            -moz-box-ordinal-group: 1;      /* OLD - Firefox 19- */
            -ms-flex-order: 1;              /* TWEENER - IE 10 */
            -webkit-order: 1;               /* NEW - Chrome */
            order: 1;                       /* NEW, Spec - Opera 12.1, Firefox 20+ */
        }
        .flex-2 {
            -webkit-box-ordinal-group: 2;   /* OLD - iOS 6-, Safari 3.1-6 */
            -moz-box-ordinal-group: 2;      /* OLD - Firefox 19- */
            -ms-flex-order: 2;              /* TWEENER - IE 10 */
            -webkit-order: 2;               /* NEW - Chrome */
            order: 2;                       /* NEW, Spec - Opera 12.1, Firefox 20+ */
        }
        </style>
    </head>
    <body>
        <p>平均水平分3栏</p>
        <div class="flex-h w150 h50">
            <div class="flex1">文字文字文字文字文字文字文字</div>
            <div class="flex1">text text text text text text text text</div>
            <div class="flex1">文字文字文字文字文字文字文字</div>
        </div>
        <p>平均水平分4栏</p>
        <div class="flex-h w150 h50">
            <div class="flex1">文字文字文字文字文字文字文字</div>
            <div class="flex1">text text text text text text text text</div>
            <div class="flex1">文字文字文字文字文字文字文字</div>
            <div class="flex1">text text text text text text text text</div>
        </div>
        <p>纵向排列</p>
        <div class="flex-v w150 h50">
            <div class="flex1 w60 h50">文字文字文字文字文字文字文字</div>
            <div class="flex1 w60 h50">text text text text text text text text</div>
            <div class="flex1 w60 h50">文字文字文字文字文字文字文字</div>
            <div class="flex1 w60 h50">text text text text text text text text</div>
        </div>
        <p>横向排列 + 横向换行</p>
        <div class="flex-h w150 h50 flex-hw">
            <div class="w60 h50">文字文字文字文字文字文字文字</div>
            <div class="w60 h50">text text text text text text text text</div>
            <div class="w60 h50">文字文字文字文字文字文字文字</div>
            <div class="w60 h50">text text text text text text text text</div>
        </div>
        <h6>Android4.2.2不支持换行</h6>
        <p>竖直居中</p>
        <div class="flex-h flex-vc w200 h50">
            <div class="w60 h30">文字文字文字文字文字文字文字</div>
            <div class="w60 h30">text text text text text text text text</div>
        </div>
        <p>水平居中</p>
        <div class="flex-h flex-hc w200 h50">
            <div class="w60 h30">文字文字文字文字文字文字文字</div>
            <div class="w60 h30">text text text text text text text text</div>
        </div>
        <p>居中</p>
        <div class="flex-h flex-hc flex-vc w200 h50">
            <div class="w60 h30">文字文字文字文字文字文字文字</div>
            <div class="w60 h30">text text text text text text text text</div>
        </div>
        <p>改变顺序(栅格布局,最终效果英文应该在左边)</p>
        <div class="flex-h w200 h50">
            <div class="flex1 flex-2">文字文字文字文字文字文字文字</div>
            <div class="flex1 flex-1">text text text text text text text text</div>
        </div>
        <h6>Android4.2.2下伪元素位置表现不一致</h6>
    </body>
    </html>

     

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-5-2 09:03 , Processed in 0.083425 second(s), 29 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表