flex布局示例

来自:受权地址
做者:水牛01248html

几个横排元素在竖直方向上居中android

display: flex;
flex-direction: row;//横向排列
align-items: center;//垂直方向上居中

在母控件的正中:至关于android中的RelativeLayout的app

display: flex;
flex-direction: row;//横向排列
justify-content: center;//水平居中
align-items: center;//垂直方向上居中

自定义modal的一个标题栏,带图标的标题居中,右边有关闭按钮布局

绕的一个坑: 中间的用div包裹,flex布局可实现centerInParent效果,右边的用position:
absolute;right: 0.75rem,能够实现关闭按钮在右边,可是脱离的文档流,居中很差弄. 能不能不脱离flex的文档流?flex

能够的,左边加一个空的div,就能够对称了,用flex布局的justify-content: space-between,就能均匀排列了.spa

<div style="display: flex;flex-direction: row;justify-content: space-between;align-items: center;
            align-content: center;background-color: #0d88c1;padding-left: 0.75rem;padding-right: 0.75rem">
                <div></div>
                <div style="display: flex;flex-direction: row;justify-content: center;align-items: center;background-color: #1f9d85">
                    <div style="font-size: 2rem">图片</div>
                    <div >文字</div>
                </div>
                <div style="background-color: red;">x</div>
            </div>

同理,利用justify-content: space-between + align-items: center 能够实现右边垂直居中的效果:code

把左边的两个元素用div包裹,而后和右边的元素做为flex布局的两个item,用space-between撑到两边.htm

常见的tab导航栏的实现图片

clipboard.png

clipboard.png

.tab-container{
    display: flex;
    flex-direction: row;//横向排列
    flex-wrap: nowrap;//不换行
     overflow-x: scroll;//横向放不下时容许滚动
    justify-content:space-around;//各item之间被间隔包裹
    align-items: center;//垂直方向上居中
}
/*tab栏的条目数,自动均分*/
.tab-items{
    flex: 1 0 200rpx;//自己大小200rpx,能够扩张(1:好比只有两个tab时,平分width),不准压缩(0)
    text-align: center;
    padding-bottom: 25rpx;
    padding-top: 25rpx;
    font-size: 30rpx;
    color: #333333;
}

布局练习:
1.item布局ip

clipboard.png

转自:转载地址

相关文章
相关标签/搜索