英文:
What does the Class Tag mean on MudBlazor Components?
问题
我使用他们在这里描述的dotnet模板创建了一个新的MudBlazor项目。我打开了项目并注意到MudContainer属性上的类标签<MudContainer MaxWidth="MaxWidth.Large" Class="my-16 pt-16">
,我对这是什么感到困惑,而且在我的解决方案中找不到任何名为"my-16"或"pt-16"的内容。
以下是更详细的代码:
MainLayout.Razor
@inherits LayoutComponentBase
<MudThemeProvider />
<MudDialogProvider />
<MudSnackbarProvider />
<MudLayout>
...(省略了额外的代码)
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.Large" Class="my-16 pt-16">
@Body
</MudContainer>
</MudMainContent>
</MudLayout>
当我在API文档这里中搜索,并查找具有此标签的任何其他组件时,我只找到了这个描述:"由空格分隔的用户类名称。"这对我没有帮助。然后,我添加了一个名为MainLayout.razor.css
的文件,其中包含此测试类:
.test {
background-color: red !important;
}
并尝试将"test"添加到类标签中,但没有任何效果。总之,我完全不清楚两个问题:
- 类标签的含义是什么?
- 我在哪里可以找到提供的"my-16"和"pt-16"类?
英文:
I created a new MudBlazor project using the dotnet template they describe here. I opened up the project and noticed the class tag on the MudContainer property <MudContainer MaxWidth="MaxWidth.Large" Class="my-16 pt-16">
I was confused on what this was, and I couldn't find anything in my solution with the name "my-16" or "pt-16".
Here's a more extended code:
MainLayout.Razor
@inherits LayoutComponentBase
<MudThemeProvider />
<MudDialogProvider />
<MudSnackbarProvider />
<MudLayout>
... (Extra code taken out)
<MudMainContent>
<MudContainer MaxWidth="MaxWidth.Large" Class="my-16 pt-16">
@Body
</MudContainer>
</MudMainContent>
</MudLayout>
When I searched the API documentation here, and any other component that has this tag, all I found was this description: "User class names, separated by space." which I got no help from. I then added in a file called MainLayout.razor.css
with this test class:
.test {
background-color: red !important;
}
and tried to put test into the class tag, but it had no effect. Overall I'm at a totall loss on two things:
- What does the class tag mean?
- Where can I find the
my-16
andpt-16
classes provided?
答案1
得分: 1
- "class"(小写)是HTML class属性,而"Class"(大写C)是MudBlazor的属性。
- MudBlazor组件公开了"Class"属性,它会添加到组件底层HTML元素的"class"属性中。
- 在代码中,
.AddClass(Class)
是你在"Class"属性中定义的类添加的地方。 - 类似于向HTML元素添加类,你可以使用MudBlazor组件的"Class"属性来添加你的类,例如通过用空格分隔它们。
"my-16"和"pt-16"是CSS实用类,专门用于间距。
你可以阅读关于CSS实用类是什么的文章,简而言之,它们也是你可以使用的类。
英文:
> What does the class tag mean?
There is class
(lowercase), which is an HTML class attribute and there is Class
(capital C), which is a MudBlazor property.
MudBlazor components expose the Class
property which get added on top of the components underlying HTML elements class
attribute.
The code below is a snippet of MudContainer
component.
<div @attributes="UserAttributes" class="@Classname" style="@Style">
@ChildContent
</div>
@code {
string Classname =>
new CssBuilder("mud-container")
.AddClass($"mud-container-fixed", Fixed)
.AddClass($"mud-container-maxwidth-{MaxWidth.ToDescriptionString()}", !Fixed)
.AddClass(Class)
.Build();
}
.AddClass(Class)
<- this is where the classes you define in the Class property get added.
So similar to how you add classes to an HTML element, you use MudBlazor components Class
property to add your classes. i.e. by seperating them with spaces.
<div class="bio-text bio-heading">My Bio</div>
<MudText Class="bio-text bio-heading">My Bio</MudText>
> Where can I find the my-16 and pt-16 classes provided?
my-16
and pt-16
are CSS utility classes, these two are specifically used for spacing.
You should have a read through what are CSS utility classes. In a few words, they're also classes that you can use.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论