admin管理员组文章数量:1332361
I have a app at and cannot seem to get it to compile much less assign a neutral color to the navbar. I can change it from light to dark mode, but want something other than a light pink as the background.
this is the style, an in the same folder i have my m3-style.scss. I am NOT using any Material 2 styling, strictly Material 3, so I don't need backward compatability.
enter code here
@use 'sass:map';
@use '@angular/material' as mat;
@use 'm3-theme.scss';
$typography-config: (
plain-family: 'Edu AU VIC WA NT Pre',
brand-family: 'Edu AU VIC WA NT Pre',
); !
$typography-config-secondary: (
plain-family: Roboto,
brand-family: Open Sans,
bold-weight: 900,
medium-weight: 500,
regular-weight: 300,
);
$theme: mat.define-theme(
(
color: (
theme-type: light,
primary: mat.$azure-palette,
tertiary: mat.$blue-palette,
),
typography: $typography-config,
)
);
$theme-secondary: mat.define-theme(
(
color: (
primary: mat.$violet-palette,
tertiary: mat.$magenta-palette,
),
typography: $typography-config-secondary,
)
);
body {
font-family: Roboto, 'Helvetica Neue', sans-serif;
margin: 0;
padding: 30px;
height: 100%;
@include mat.all-component-themes($theme);
@include mat.toolbar-theme($theme-secondary);
}
html {
height: 100%;
}
//THIS Is what I am trying to use for the toolbar and I have a toolbar theme above that doesn't work either
mat-toolbar {
background-color: mat-color($neutral, 900); // Adjust the shade as needed
}
@include mat.core();
@include mat.typography-hierarchy($theme); // <- notice!
Any assistance would be appreciated
Thanks
I have a app at https://stackblitz/edit/etnmae-xjweyt and cannot seem to get it to compile much less assign a neutral color to the navbar. I can change it from light to dark mode, but want something other than a light pink as the background.
this is the style, an in the same folder i have my m3-style.scss. I am NOT using any Material 2 styling, strictly Material 3, so I don't need backward compatability.
enter code here
@use 'sass:map';
@use '@angular/material' as mat;
@use 'm3-theme.scss';
$typography-config: (
plain-family: 'Edu AU VIC WA NT Pre',
brand-family: 'Edu AU VIC WA NT Pre',
); !
$typography-config-secondary: (
plain-family: Roboto,
brand-family: Open Sans,
bold-weight: 900,
medium-weight: 500,
regular-weight: 300,
);
$theme: mat.define-theme(
(
color: (
theme-type: light,
primary: mat.$azure-palette,
tertiary: mat.$blue-palette,
),
typography: $typography-config,
)
);
$theme-secondary: mat.define-theme(
(
color: (
primary: mat.$violet-palette,
tertiary: mat.$magenta-palette,
),
typography: $typography-config-secondary,
)
);
body {
font-family: Roboto, 'Helvetica Neue', sans-serif;
margin: 0;
padding: 30px;
height: 100%;
@include mat.all-component-themes($theme);
@include mat.toolbar-theme($theme-secondary);
}
html {
height: 100%;
}
//THIS Is what I am trying to use for the toolbar and I have a toolbar theme above that doesn't work either
mat-toolbar {
background-color: mat-color($neutral, 900); // Adjust the shade as needed
}
@include mat.core();
@include mat.typography-hierarchy($theme); // <- notice!
Any assistance would be appreciated
Thanks
Share Improve this question edited Nov 21, 2024 at 3:22 Naren Murali 58.9k5 gold badges44 silver badges77 bronze badges asked Nov 21, 2024 at 2:29 Roger iRoger i 1278 bronze badges1 Answer
Reset to default 0I notice that you are not using the custom theme you created, so I modified the code to use the custom theme.
@use "m3-theme.scss" as custom-theme;
...
...
$theme-secondary: mat.define-theme(
(
color: (
primary: custom-theme.$primary-palette,
tertiary: custom-theme.$tertiary-palette,
),
typography: $typography-config-secondary,
)
);
To configure the customization, please follow the below steps, angular material got new upgrades on version 19 and it makes theming 100 times easier.
First visit the documentation page, for you it's mat toolbar - documentation then visit the
styling
tab.Here at the bottom you will find
Tokens supported by toolbar-overrides
which contains the tokens for customization of the toolbar. Since we are customizing the background color, we choosecontainer-background-color
.Now we have the token name, we can refer the new Theming guide using component tokens then add the
mat.<<feature name>>-overrides(
method to add the custom styles. To get the theme color I use themat.get-theme-color
and configure the token with this obtained property.mat-toolbar { @include mat.toolbar-overrides( ( container-background-color: mat.get-theme-color($theme-secondary, neutral, 96), ) ); }
After this your have customized your navbar based on a overridden theme.
Full Code:
@use "sass:map";
@use "@angular/material" as mat;
@use "m3-theme.scss" as custom-theme;
$typography-config: (
// <- notice!
plain-family: "Edu AU VIC WA NT Pre",
// <- notice!
brand-family: "Edu AU VIC WA NT Pre",
// <- notice!
); // <- notice!
$typography-config-secondary: (
plain-family: Roboto,
brand-family: Open Sans,
bold-weight: 900,
medium-weight: 500,
regular-weight: 300,
);
$theme: mat.define-theme(
(
color: (
theme-type: light,
primary: mat.$magenta-palette,
tertiary: mat.$violet-palette,
),
typography: $typography-config,
)
);
$theme-secondary: mat.define-theme(
(
color: (
primary: custom-theme.$primary-palette,
tertiary: custom-theme.$tertiary-palette,
),
typography: $typography-config-secondary,
)
);
body {
font-family: Roboto, "Helvetica Neue", sans-serif;
margin: 0;
padding: 30px;
height: 100%;
@include mat.all-component-themes($theme);
@include mat.toolbar-theme($theme-secondary);
}
html {
height: 100%;
}
mat-toolbar {
@include mat.toolbar-overrides(
(
container-background-color:
mat.get-theme-color($theme-secondary, neutral, 96),
)
);
}
@include mat.core();
@include mat.typography-hierarchy($theme); // <- notice!
Stackblitz Demo
本文标签: angularWhy does the navbar not take the theme I am trying to assignStack Overflow
版权声明:本文标题:angular - Why does the navbar not take the theme I am trying to assign - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742317856a2452176.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论