reactjs - React Native alignSelf center and stretch to maxWidth? -


i have following

        <view style={{maxwidth: 700}}>           <view style={{backgroundcolor: 'red', flexdirection: 'row', justifycontent: 'space-between'}}>             <text>left item</text>             <text>right item</text>           </view>         </view> 

which working i'd expect on large device (vertical black lines edges of emulator screen).

enter image description here

all center on screen.

when attempt adding alignself: 'center' parent

        <view style={{maxwidth: 700, alignself: 'center'}}>           <view style={{backgroundcolor: 'red', flexdirection: 'row', justifycontent: 'space-between'}}>             <text>left item</text>             <text>right item</text>           </view>         </view> 

the width lost.

enter image description here

i assume because default alignself 'stretch'. there way both stretch content use maxwidth , center on screen?

try using flex:1 along maxwidth both make stretch limit width 700

<view style={{flexdirection:'row', alignitems: 'center', justifycontent: 'center'}}>     <view style={{flex:1, maxwidth: 700, backgroundcolor:'red', flexdirection:'row', justifycontent:'space-between'}}>         <text>left item</text>         <text>right item</text>     </view> </view> 

Comments

Popular posts from this blog

php - Auto increment employee ID -

php - isset function not working properly -

javascript - Thinglink image not visible until browser resize -