美文网首页
flex布局

flex布局

作者: QinRenMin | 来源:发表于2018-08-08 17:45 被阅读0次
  • flexDirection
    作用:决定布局的主轴
    column:从上往下堆叠 主轴:纵向 默认值
    row : 从左至右堆叠 主轴:横向
    column.png
    row.png
  • justifyContent
    作用:决定子元素沿着 主轴 方向的排列方式

flex-start:从主轴处开始

column_start.png
row_start.png

flex-end:从主轴结束处开始

column_end.png row_end.png

center:主轴中心部

colmun_center.png
row_center.png

space-around:

column_around.png
row_around.png
space-between
column_between.png row_between.png

space-evenly

column_evenly.png
row_evenly.png
补充内容:
space-between
元素会平均地分布在行(列)里。如果最左边的剩余空间是负数,或该行只有一个子元素,则该值等效于'flex-start';超过一个元素,则先确定首末元素的位置,然后再均分剩余空白位置
0-x-xx-0
space-around
弹性盒子元素会平均地分布在行里,两端保留子元素与子元素之间间距大小的一半。如果最左边的剩余空间是负数,或该行只有一个伸缩盒项目,则该值等效于'center'。在其它情况下,伸缩盒项目则平均分布,并确保两两之间的空白空间相等,同时第一个元素前的空间以及最后一个元素后的空间为其他空白空间的一半。
x-2x-2x-x
space-evenly
均匀分布所有
x-x-x-x

代码例子:

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});
import React, { Component } from 'react';
import { StyleSheet,View } from 'react-native';

export default class App extends Component {
    render() {
        return (
            <View style = {S.container}>
                <View style = {S.subBox}>

                </View>
                <View style = {S.centerBox}>

                </View>
                <View style = {S.bottomBox}>

                </View>
            </View>
        );
    }
}

const S = StyleSheet.create({
    container:{
        flex:1,
        backgroundColor:'pink',
        flexDirection: 'column',
//        flexDirection: 'row',
        justifyContent: 'flex-start',
//        justifyContent: 'flex-end',
//        justifyContent: 'center',
//        justifyContent: 'space-around',
//        justifyContent: 'space-between',
//        justifyContent: 'space-evenly',
     
    },
    subBox:{
        height:100,
        width: 100,
        backgroundColor: 'red'
    },
    centerBox:{
        height:100,
        width:100,
        backgroundColor:'blue',
    },
    bottomBox:{
        height:100,
        width:100,
        backgroundColor:'yellow',
    },
});

  • alingItems
    作用:决定子元素沿着次轴的排列方式
    1 flex-start
    2 flex-end
    3 center
    4 stretch
    注意:若要stretch生效,子元素在次轴方向不能有固定的尺寸

相关文章

  • flex布局

    认识flex布局 flex布局(Flexible 布局,弹性布局)开启了flex布局的元素叫flex contai...

  • 初见FLEX

    FLEX布局 一种新的布局方式,flex布局 flex布局与方向无关 flex布局可以实现空间自动分配、自动对齐。...

  • Flex 布局教程

    一、Flex 布局教程:语法篇 Flex 布局教程:语法篇 二、Flex 布局教程:实例篇 Flex...

  • css flex布局详解

    css flex布局详解 css flex布局详解1css flex布局详解2

  • Flex

    阮一峰-Flex布局 阮一峰-Flex布局实例教程 Flex布局 块级元素 行内元素 注意,设为 Flex 布局...

  • flex布局学习笔记

    经典教程 Flex 布局教程:语法篇Flex 布局教程:实例篇flex布局游戏 理解 flex布局实现需要至少两层...

  • 6Flex 布局

    Flex,(Flexible Box),意为"弹性布局"采用 Flex 布局的元素,为 Flex 容器(flex ...

  • css flex

    css flex布局 采用 Flex 布局的元素,称为 Flex 容器(flex container),简称“容器...

  • Flex布局(语法篇)

    一、介绍Flex布局 什么是Flex布局呢?Flex布局:又称弹性布局,它是Flexible Box 的缩写,它为...

  • Day02_flex布局

    一、flex布局介绍: 1、又名Flexible 布局,弹性布局;2、开启了 flex 布局的元素叫 flex c...

网友评论

      本文标题:flex布局

      本文链接:https://www.haomeiwen.com/subject/klrxbftx.html