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

MudBlazor组件尺寸与布局配置:实现并排选择框及居中元素

MudBlazor布局调整方案

要实现两个MudSelect并排、复选框和按钮居中的布局,你可以利用MudBlazor的布局组件来调整,下面是修改后的完整代码:

<MudGrid Spacing="2">
    <MudItem xs="6">
        <MudSelect T="MailboxUser" Placeholder="Select Forward From Mailbox" Variant="Variant.Outlined" Label="Forward From" 
                   @bind-Value="@SelectedForwardFrom" AnchorOrigin="Origin.BottomCenter" Dense="true" FullWidth="true">
            @foreach (var user in SortedUsers)
            {
                <MudSelectItem Value="@user" >@user.DisplayName (@user.PrimarySmtpAddress)</MudSelectItem>
            }
        </MudSelect>
    </MudItem>
    <MudItem xs="6">
        <MudSelect T="MailboxUser" Placeholder="Select Forward To Mailbox" Variant="Variant.Outlined" Label="Forward To" 
                   @bind-Value="@SelectedForwardTo" AnchorOrigin="Origin.BottomCenter" Dense="true" FullWidth="true">
            @foreach (var user in SortedUsers)
            {
                <MudSelectItem Value="@user">@user.DisplayName (@user.PrimarySmtpAddress)</MudSelectItem>
            }
        </MudSelect>
    </MudItem>
</MudGrid>

<MudFlex JustifyContent="JustifyContent.Center" MarginTop="Margin.Top2">
    <MudCheckBox @bind-Checked="@SendToBoth" Color="Color.Primary" Label="Deliver To Both Mailboxes"></MudCheckBox>
</MudFlex>

<MudFlex JustifyContent="JustifyContent.Center" MarginTop="Margin.Top2" Gap="Gap.Small">
    <MudButton Variant="Variant.Filled" Color="Color.Primary" @onclick="HandleSetForwardAction">Set Forward</MudButton>
    <MudButton Variant="Variant.Filled" Color="Color.Primary" @onclick="HandleRefreshAction">Refresh</MudButton>
</MudFlex>

关键设置说明

  • 并排布局:使用MudGrid和MudItem实现响应式排列,xs="6"表示在最小屏幕尺寸下每个元素占一半宽度,大屏幕自动并排、小屏幕自动堆叠。将MudSelect的FullWidth设为true,让组件填满所在MudItem的宽度,保持布局整齐。
  • 居中对齐:用MudFlex包裹复选框和按钮,通过JustifyContent="JustifyContent.Center"实现水平居中,MarginTop用来和上方选择框拉开间距,按钮组添加Gap属性控制按钮间的距离。

内容的提问来源于stack exchange,提问作者Tom Gordon

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 00:13:15