材料角4的扩展面板 [英] Expansion-panel from material angular 4

查看:70
本文介绍了材料角4的扩展面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在material 2.0.0-beta.12上有一个有角度的4.4.4应用程序,我想使用材料设计中的mat-expansion-panel.

I hava an angular 4.4.4 application with material 2.0.0-beta.12 and I want to use the mat-expansion-panel from material design.

这是我的代码:

           <mat-expansion-panel class="parametersPanel">
                    <mat-expansion-panel-header>
                        <mat-panel-title>
                            PARAMETERS
                        </mat-panel-title>
                    </mat-expansion-panel-header>
                    <table style="width:100%">
                        <tbody>
                            <tr class="parameterListItem">
                                <td class="icon"><img src="assets/images/alert.png"></td>
                                <td class="parameterName">Parameter 1</td>
                                <td class="parameterValue">Value</td>
                                <td class="unit">unit</td>
                            </tr>                        
                        </tbody>
                    </table>
            </mat-expansion-panel>

因此效果很好,但是有可能从浏览器margin: 0 24px 16px;中删除mat-expansion-panel-body中的边距?

So it works well but it possible to remove the margin in the mat-expansion-panel-body which has, from the browser margin: 0 24px 16px; ?

推荐答案

在您的style.css或组件样式中,您需要添加以下CSS:

In your style.css or your components style you need to add the following css:

/deep/ .parametersPanel .mat-expansion-panel-body {
    padding: 0;
}

这是由于视图封装所致.您可以在此处了解更多信息: https://angular.io/guide/component-styles

This is due to view encapsulation. You can read more about this here: https://angular.io/guide/component-styles

更新:

不建议使用/deep/::ng-deep来修改材料组件的样式.参见此链接.

The use of /deep/, ::ng-deep to modify the styles of material components has been deprecated. See this link.

但是,使用@angular/core ^6.1.0@angular/material ^6.4.6,我可以更改Angular Material的Expansion面板的样式,而无需添加任何特定的内容.看来您现在可以简单地在组件css文件中更改样式.所以这应该工作:

However, using @angular/core ^6.1.0 and @angular/material ^6.4.6 I was able to change the style of Angular Material's Expansion panel without having to add anything specific. It seems like you can now simply change the style in your components css file. So this should work:

.mat-expansion-panel-body {
    padding: 0;
}

您可以在此处阅读有关/deep/::ng-deep弃用的更多信息,此处.

You can read here for more information about the deprecation of /deep/, ::ng-deep here.

这篇关于材料角4的扩展面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆