简体   繁体   English

如何在 ngx-admin 主题中使用主题颜色

[英]How to use theme colors in ngx-admin theme

I am new to Angular and I am trying to learn it by using ngx-admin theme.我是 Angular 的新手,我正在尝试使用ngx-admin主题来学习它。 It uses Sass for styling and in one of my components I want to set background color of div.它使用 Sass 进行样式设置,在我的一个组件中,我想设置 div 的背景颜色。 However I want to use one of the colors provided by the theme so that if user toggles the theme the color can change.但是我想使用主题提供的一种颜色,这样如果用户切换主题,颜色就可以改变。 I cannot figure out how to use global colors of the theme in my component's scss file.我无法弄清楚如何在组件的 scss 文件中使用主题的全局颜色。

This is what I want这就是我要的

.product-container{
    background:#3d3780; // Instead of using a hard coded color, I want to use theme color here
} 

Ok I was able to find out how to use theme global colors.好的,我能够找到如何使用主题全局颜色。

Firs you need to import global theme styles by importing首先需要通过导入导入全局主题样式

@import '~@nebular/theme/styles/theming';
@import '~@nebular/theme/styles/themes';

Then I can set color like this然后我可以像这样设置颜色

@include nb-install-component() {
    .product-container{
        background:nb-theme(color-bg);
    }
  }

We need to wrap our styles inside the @include nb-install-component() call so that styles are refreshed when user changes theme.我们需要将我们的样式包装在 @include nb-install-component() 调用中,以便在用户更改主题时刷新样式。

For anyone interested in further reading, here is the official documentation of the theme.对于任何有兴趣进一步阅读的人, 这里是该主题的官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM