gpt4 book ai didi

css - 如何对齐 React Flexbox 中的文本?

转载 作者:太空宇宙 更新时间:2023-11-04 08:50:49 27 4
gpt4 key购买 nike

我正在使用 react-flexbox-grid我当前的布局看起来像

const SpicyMenu = (props) => (

<List>
{props.foodItems.map(foodItem => <SpicyMenuItem key={foodItem.name} {...foodItem}/>)}
</List>
);

const SpicyMenuItem = (props) => (
<Grid fluid>
<Row center="lg">
<Col xs={3} sm={3} lg={2}><Avatar src={props.image}/></Col>
<Col xs={6} sm={6} lg={4}>
<Row around="lg">
<Col>{props.name}</Col>
</Row>

</Col>
<Col xs={3} sm={3} lg={2}>
<div>{props.price}</div>
</Col>
</Row>
</Grid>
);

export default SpicyMenu;

当我在浏览器中查看时,我看到文本没有在框的中间对齐 enter image description here enter image description here

我的代码在 https://github.com/hhimanshu/spicyveggie/tree/menumenu 分支中可用

如何使文本在 Col 的中心对齐?谢谢

最佳答案

要居中对齐元素,父 div 可以使用 align-items: center;

参见示例:https://codepen.io/amboy00/pen/GmpoLy

关于css - 如何对齐 React Flexbox 中的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43461494/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com