React Native absolute positioning horizontal centre

后端 未结 7 767
栀梦
栀梦 2021-01-30 06:23

It seems that with position:absolute in use an element cannot be centred using justifyContent or alignItems. There\'s a workaround to use

7条回答
  •  无人及你
    2021-01-30 06:31

    It's very simple really. Use percentage for width and left properties. For example:

    logo : {
      position: 'absolute',
      top : 50,
      left: '30%',
      zIndex: 1,
      width: '40%',
      height: 150,
    }
    

    Whatever width is, left equals (100% - width)/2

提交回复
热议问题