简体   繁体   English

角度材料md-card-header背景

[英]Angular Material md-card-header background

I am developing a small AngularJS application using angular-material. 我正在使用角度材料开发一个小的AngularJS应用程序。 The problem is I cannot figure out how to properly set the background-color of the md-card-header using the color palette defined in my config. 问题是我无法弄清楚如何使用我的配置中定义的调色板正确设置md-card-header的背景颜色。

$mdThemingProvider.theme('default')
    .primaryPalette('blue')
    .accentPalette('pink');

Basically I want to set the primary color as the background color of the card header. 基本上我想将主要颜色设置为卡片头的背景颜色。 I could of course copy the RGB value, create a class and set the color using this class. 我当然可以复制RGB值,创建一个类并使用这个类设置颜色。 However, I would loose the benefit of changing the theme at runtime or at least I would have to manually change the color whenever I change my theme. 但是,我会失去在运行时更改主题的好处,或者至少每当我更改主题时我都必须手动更改颜色。

How can I set md-colors to any element, especially the md-card-header? 如何将md-colors设置为任何元素,尤其是md-card-header?

You can not color backgrounds in angular-material as of yet. 你还不能在角度材料中为背景着色。 For your example I would work around this by using a md-toolbar . 对于您的示例,我将通过使用md-toolbar解决此问题。 You can use class="md-warn/md-primary/md-accent" to style it with the colors from your palette. 您可以使用class="md-warn/md-primary/md-accent"使用调色板中的颜色对其进行样式设置。

<md-card>
  <md-toolbar class="md-warn" style="border-radius: 3px 3px 0 0">
    <md-card-header>
      <md-card-avatar>
        <img class="md-user-avatar" src="...">
        </md-card-avatar>
        <md-card-header-text>
          <span class="md-title">User</span>
          <span class="md-subhead">subhead</span>
        </md-card-header-text>
      </md-card-header>
    </md-toolbar>

Update: 更新:

Angular-material just added a color service and a directive to use the colors defined in a theme anywhere in your code (1.1.0-rc4). Angular-material刚刚添加了一个颜色服务和一个指令 ,用于在代码中的任何位置使用主题中定义的颜色(1.1.0-rc4)。

You can now do <md-card-header md-colors="::{backgroundColor: 'default-primary-700'}"> . 你现在可以做<md-card-header md-colors="::{backgroundColor: 'default-primary-700'}">

I updated the codepen. 我更新了codepen。

http://codepen.io/kuhnroyal/pen/pygvyR http://codepen.io/kuhnroyal/pen/pygvyR

check https://material.angularjs.org/latest/Theming/02_declarative_syntax 检查https://material.angularjs.org/latest/Theming/02_declarative_syntax

Theming in angular material apply to this 角形材料的主题适用于此

  • md-button MD-按钮
  • md-checkbox MD-复选框
  • md-progress-circular MD-进展圆形
  • md-progress-linear MD-进展线性
  • md-radio-button MD-单选按钮
  • md-slider MD-滑块
  • md-switch MD-开关
  • md-tabs MD-标签
  • md-text-float MD-文本浮动
  • md-toolbar MD-工具栏

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

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