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?
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
is used to center your content and control its width. You have two options for sizing the content:
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.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.).
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.
You can visualize the difference between MudBlazor's grid and container components in the animation below:
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With