css - 修改 MatBlazor 应用程序的外观

标签 css blazor blazor-webassembly matblazor

我正在尝试弄清楚如何更改使用 MatBlazor 的 Blazor 应用程序中的颜色,以使用 Google 的 Material Design 创建 Blazor 应用程序。

我已使用 Blazor WebAssembly 元素在 Visual Studio 中创建了一个新元素。我添加了 MatBlazor NuGet 包,并进行了必要的更改以添加 MAtBlazor css 和 js 文件。

然后我替换了 Index.razor 的内容以包含 MatBlazor 组件:

@page "/"

<MatAppBarContainer>
    <MatAppBar Class="main-app-bar" Fixed="true">
        <MatAppBarRow>
            <MatAppBarSection>
                <MatIconButton Icon="menu"></MatIconButton>
                <MatAppBarTitle>MatBlazor - Material Design components for Blazor</MatAppBarTitle>
            </MatAppBarSection>
            <MatAppBarSection Align="@MatAppBarSectionAlign.End">
                <MatIconButton Icon="favorite"></MatIconButton>
            </MatAppBarSection>
        </MatAppBarRow>
    </MatAppBar>

    <MatAppBarContent>
        Content
    </MatAppBarContent>
</MatAppBarContainer>

现在作为练习,我想更改 MatAppBar 的背景和文本颜色:

.main-app-bar {
    background-color: red;
    color: gold;
}

.mdc-top-app-bar {
    background-color: red;
    color: gold;
}

我已将这些 CSS 类定义添加到 app.css 以及 MainLayout.razor.css 和 NavMenu.razopr.css 中,但没有效果。

如何设置 MatBlazor 组件的 CSS 属性?

最佳答案

无需CSS编辑,只需使用MatThemeProvider服务即可: https://www.matblazor.com/Themes

这将更改整个应用的配色方案,由于您使用的是 Material design,因此建议您这样做。

关于css - 修改 MatBlazor 应用程序的外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65084105/

相关文章:

jquery - 该网站使用了哪种效果?

html - 如何从 Angular 落移除部分边框?

javascript - 是否可以在 Blazor 中将导出的 JavaScript 模块类导入为互操作类?

httpclient - 如何解决 WebAssembly 应用程序中与 HttpClient 相关的错误

blazor - 在 Blazor 中使用组件时从子级到父级进行通信

html - 伪元素的 z-index 问题

html - 将多列 div 包裹在图像周围

asp.net-core - blazor 中非 bool 值的条件属性

webassembly - Blazor 中有没有办法将 wasm-function(#) 映射回 c# 方法?

json.net - 你如何在 Blazor WebAssemby 应用程序中实现 System.Text.Json.Serialization.ReferenceHandler.Preserve