• css样式--flex布局[css3]


    说起css3就必须提到flex布局,特别是在移动端领域,用得非常多,这里写了一套flex布局兼容(并非全兼容),自己用过之后感觉良好;

    /* ============================================================
       flex:定义布局为盒模型
       flex-v:盒模型垂直布局
       flex-1:子元素占据剩余的空间
       flex-align-center:子元素垂直居中
       flex-pack-center:子元素水平居中
       flex-pack-justify:子元素两端对齐
       兼容性:ios 4+、android 2.3+、winphone8+
       ============================================================ */
    .flex{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}
    .flex-v{-webkit-box-orient:vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}
    .flex-1{-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;}
    .flex-align-center{-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;}
    .flex-pack-center{-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}
    .flex-pack-justify{-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;}
    

     

    两端对齐可以用这种方法:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" name="viewport">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <style type="text/css">
    /* ============================================================
       flex:定义布局为盒模型
       flex-v:盒模型垂直布局
       flex-1:子元素占据剩余的空间
       flex-align-center:子元素垂直居中
       flex-pack-center:子元素水平居中
       flex-pack-justify:子元素两端对齐
       兼容性:ios 4+、android 2.3+、winphone8+
       ============================================================ */
    .flex{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}
    .flex-v{-webkit-box-orient:vertical;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}
    .flex-1{-webkit-box-flex:1;-webkit-flex:1;-ms-flex:1;flex:1;}
    .flex-align-center{-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;}
    .flex-pack-center{-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;}
    .flex-pack-justify{-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;}
    </style>
    </head>
    <body>
    
    <div class="flex flex-pack-justify">
        <div>模块一</div>
        <div>模块二</div>
        <div>模块三</div>
        <div>模块四</div>
    </div>
    
    </body>
    </html>
    

      

    使用注意:

    • flex下的子元素必须为块级元素,非块级元素在android2.3机器下flex失效
    • flex下的子元素宽度和高度不能超过父元素,否则会导致子元素定位错误,例如水平垂直居中

    fixed BUG

    • ios下fixed元素容易定位出错,软键盘弹出时,影响fixed元素定位
    • android下fixed表现要比iOS更好,软键盘弹出时,不会影响fixed元素定位
    • ios4下不支持position:fixed

    解决方案

    • 可用isroll.js,暂时没有完美解决方案。

    资料参考:

    移动端web页面使用position:fixed问题总结 #2

    --任何组织或个人分享、转载本博客内容,请务必以链接方式注明出处:来自博客园--下雨天的太阳(http://www.cnblogs.com/doomjx/)--
    --请勿以任何形式修改内容(包括文字和图片)--
  • 相关阅读:
    常看本地是否安装Git和maven工具
    Git 安装和使用Tips
    Jmeter 获取系统时间,和对系统时间进行增减时间
    Java 中的系统时间
    Go语言
    数据拆分之 垂直拆分 and 水平拆分
    在Windows和UNIX下利用PHP和LDAP进行身份验证
    Linux中使用crontab命令定时执行shell脚本或其他Linux命令
    php empty()和isset()的区别
    php 判断是否get传值的参数是否存在
  • 原文地址:https://www.cnblogs.com/doomjx/p/5773136.html
Copyright © 2020-2023  润新知