Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create this layout in Flexbox?

I'm trying to create this layout in Flexbox (and React Native) but I can't get it to work. Specifically, the Left and Right buttons refuse to expand to 50% of the width of the container no matter what I do. They are always the size of their content.

I'm using nested containers. The buttons are in a columnar Flex container which is nested in a row Flex container that also contains the image.

enter image description here

Here is my JSX:

  <View style={{
    display: 'flex',
    flex: 1,
    flexDirection: 'column'}}>
      <Image
        style={{flex: 1, zIndex: 1, width: '100%', height: '100%'}}
        resizeMode='cover'
        resizeMethod='resize'
        source={require('./thumbs/barry.jpg')}
      />
      <View style={{
        display: 'flex',
        flexDirection: 'row',
        flex: 0,
        width: '100%',
        height: 100}} >
          <Button style='flex: 1' title="LEFT"  onPress={() => {}} />
          <Button style='flex: 1' title="RIGHT" onPress={() => {}} />
      </View>
  </View>

All replies are much appreciated...

like image 790
Barry Fruitman Avatar asked Nov 08 '22 08:11

Barry Fruitman


1 Answers

Maybe this will help you:

.container{
  display: flex;
  flex-wrap: wrap;
  width: 500px;
}

.image{
  height: 500px;
  flex-basis: 100%;
  background-color: green;
}

.button{
  box-sizing: border-box;
  flex-basis: 50%;
  height: 100px;
  background-color: red;
  border: solid 1px black;
}
<div class="container">
  <div class="image"></div>
  <div class="button"></div>
  <div class="button"></div>
</div>

If you ever have issues with using flexbox, use this resource, it's really helpful for solving flexbox issues. Hopefully you can solve your problem now.

like image 72
Willem van der Veen Avatar answered Nov 15 '22 12:11

Willem van der Veen