最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set alignSelf for flexDirection=row - Stack Overflow

programmeradmin3浏览0评论

I want to create a View as flexDirection="row". but I cannot use alignSelf when I use flexDirection="row". now, How can I use this figure:

|                                                 |
|LeftItem-1  LeftItem-2                  RightItem|
|                                                 |

I want to create a View as flexDirection="row". but I cannot use alignSelf when I use flexDirection="row". now, How can I use this figure:

|                                                 |
|LeftItem-1  LeftItem-2                  RightItem|
|                                                 |
Share edited Feb 14, 2019 at 16:27 Brian 3,9144 gold badges23 silver badges38 bronze badges asked Feb 14, 2019 at 10:15 S.M_EmamianS.M_Emamian 17.4k40 gold badges154 silver badges273 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 5

When you are using flexDirection="row" then alignSelf work vertically. When you are using flexDirection="column" then alignSelf work horizontally.

So for that, you have to use JustifyContent.

<View style={{flexDirection: "row"}}>
    <View style={{flexDirection: "row",flex:1}}>
        <Text> LeftItem-1   </Text>
        <Text> LeftItem-2   </Text>
    </View>
    <Text> LeftItem-3   </Text>
</View>

This way you can achieve your output.

You can learn more about flexbox here: https://css-tricks./snippets/css/a-guide-to-flexbox/

There are a few ways to achieve this. One simple way to achieve the layout you require would be via the following:

<View style={{ flexDirection : "row" }}>
    <Text>LeftItem-1</Text>
    <Text>LeftItem-2</Text>
    <View style={{ flex : 1 }}></View>
    <Text>RightItem</Text>
</View>

Another option would be to group the left elements in a <View> and then use the space-between - this would however add extra plexity to your view structure and styling:

 <View style={{ flexDirection : "row", justifyContent:"space-between" }}>
    <View style={{ flexDirection : "row" }}>
      <Text>1</Text>
      <Text>2</Text>
    </View>
    <Text>RightItem</Text>
</View>

Group left side in one group, and use

justify-content:space-between;

When you’re using a flexbox with flexDirection="row",

alignSelf, as well as the alignItems property, refers to how items are aligned vertically

If you want to create this exact figure, put your two left items in a div, and use

justify-content:space-between;

to set the two group far apart horizontally

发布评论

评论列表(0)

  1. 暂无评论