组件返回了以下代码:
<div style={{marginLeft: 330}}>
<PostForm />
{this.state.posts.map(post => (
<Post key={post.id} post={post} />
))}
</div>
我如何使用内联样式使postform和Post组件在所有设备上的屏幕居中。
您可以将display:'flex',justifyContent:'center',alignitems:'center'
添加到父组件(在本例中是div):
<div style={{
marginLeft: 330,
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
}}>
<PostForm />
{this.state.posts.map(post => (
<Post key={post.id} post={post} />
))}
</div>