You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Material UI Grid alignItems='flex-end' 运行效果不符合预期排查

问题原因

  • 外层Grid未添加container属性:Material UI的Grid组件只有明确声明container属性时才会作为flex容器生效,你配置的direction、alignItems等flex布局属性才会被识别,缺失该属性是核心问题。
  • 可选排查点:如果添加属性后效果仍不符合预期,可检查外层Grid是否占据了父容器的完整宽度,若外层Grid宽度仅适配内容宽度,右对齐效果无法显现,可添加width: 100%或flexGrow:1确保宽度足够。

修正后代码

export const WalletsContainer = () => {
  return (
    <Grid 
      container
      style={{ background: 'red', width: '100%' }} 
      direction="column" 
      alignItems="flex-end"
    >
      <Grid xs={2}>
        <CustomButton buttonText={t('add')} onClick={() => console.log('Add')} />
      </Grid>
      <Grid xs={2}>
        <CustomButton buttonText={t('download')} onClick={() => console.log('Download')} />
      </Grid>
    </Grid>
  );
};

内容的提问来源于stack exchange,提问作者Alex Ironside

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.10 15:24:00