Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between MudBlazor's grid and container

I'm new to MudBlazor.

In bootstrap if I want to size content for multiple breakpoints I'd use the grid (.container and then .row and .col-x).

Mudblazor has a MudGrid, but it also has a MudContainer element.

In lots of sample code I noticed that people use it instead of a grid. So in bootstrap I would have to fiddle with xs, md, etc. for it to look good on all breakpoints, but in mudblazor people seem to use just the MudContainer with MaxWidth.

The docs aren't clear on this. When would you use the MudGrid, and when the MudContainer? Are they equivalent? Why the need for the container? Is the one easier to use than the other?

like image 898
lonix Avatar asked Oct 13 '25 11:10

lonix


1 Answers

In MudBlazor, the MudGrid and MudContainer components serve different purposes, and they are not equivalent to one another. The MudContainer component is used to control the overall width and alignment of your content, while the MudGrid component is used to create responsive layouts with a 12-column grid system. Let's dive into the details of each component:

Bootstrap MudBlazor
.container MudContainer
.row MudGrid
.col-xx MudItem (with breakpoints)

MudContainer

MudContainer is used to center your content and control its width. You have two options for sizing the content:

  • Fluid: Set the MaxWidth of your container from ExtraSmall to ExtraExtraLarge according to your preference. This will allow your content to grow and shrink fluidly within the defined maximum width.
  • Fixed: The container will "snap" to the closest breakpoint. This will create a more rigid layout that adapts to specific breakpoints.

MudGrid

MudGrid is a responsive 12-point grid system, similar to the rows (row) and columns (col-xx) in Bootstrap. It is used for creating flexible layouts that adapt to different screen sizes. To control the layout at multiple breakpoints, you can use the MudItem component with different breakpoint properties (e.g., xs, md, etc.).

When to use MudContainer and MudGrid

You should use MudContainer when you want to control the overall width and alignment of your content. On the other hand, use MudGrid when you need to create responsive layouts with multiple columns that adapt to different screen sizes.

In many cases, you will use both components together. For instance, you can wrap a MudGrid inside a MudContainer to create a responsive layout with a maximum width.

However, if you already have a container set up for your content body in your MainLayout template, you may not need to use MudGrid with a container, as nesting a container into another one may result in misalignment issues.

Animation Example

You can visualize the difference between MudBlazor's grid and container components in the animation below:

Animation illustrating MudBlazor's grid and container components in various configurations.

Code for the animation example:

<MudContainer MaxWidth="MaxWidth.Small" Style="background-color: lightcoral; height: 50px;" Class="mt-2">
    MudContainer > MaxWidth="MaxWidth.Small"
</MudContainer>

<MudContainer Fixed="true" Style="background-color: darkseagreen; height: 50px;"  Class="mt-2">
    MudContainer > Fixed
</MudContainer>

<MudContainer Style="background-color:pink; height: 50px;"  Class="mt-2">
    MudGrid inside MudContainer
    <MudGrid Style="background-color: darkkhaki;">
        <MudItem xs="6">
            <MudPaper Class="d-flex align-center justify-center mud-width-full py-3">xs=6</MudPaper>
        </MudItem>
        <MudItem xs="6">
            <MudPaper Class="d-flex align-center justify-center mud-width-full py-3">xs=6</MudPaper>
        </MudItem>
    </MudGrid>
</MudContainer>

<br/><br/>MudGrid
<MudGrid Style="background-color: darkkhaki;">
    <MudItem xs="6">
        <MudPaper Class="d-flex align-center justify-center mud-width-full py-3">xs=6</MudPaper>
    </MudItem>
    <MudItem xs="6">
        <MudPaper Class="d-flex align-center justify-center mud-width-full py-3">xs=6</MudPaper>
    </MudItem>
</MudGrid>
like image 91
Ibrahim Timimi Avatar answered Oct 15 '25 21:10

Ibrahim Timimi