类标签在 MudBlazor 组件中的含义是什么?

huangapple go评论69阅读模式
英文:

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"添加到类标签中,但没有任何效果。总之,我完全不清楚两个问题:

  1. 类标签的含义是什么?
  2. 我在哪里可以找到提供的"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:

  1. What does the class tag mean?
  2. Where can I find the my-16 and pt-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.

&lt;div class=&quot;bio-text bio-heading&quot;&gt;My Bio&lt;/div&gt;

&lt;MudText Class=&quot;bio-text bio-heading&quot;&gt;My Bio&lt;/MudText&gt;

> 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.

huangapple
  • 本文由 发表于 2023年6月29日 00:20:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76575049.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定