[英]How to override styles of md-input-container in angular2?
I have the following piece of code for md-input-container using angular material design: 我有以下使用角材料设计的md-input-container代码:
<md-input-container>
<input mdInput [placeholder]="'common.password' | translate" type="password" formControlName="password" (change)="onPasswordChange($event.target.value)" required validate-onBlur/>
<md-hint *ngIf="frmLoginInfo.controls.password.pristine" class="s-text-caption s-hint">{{ 'signup.pwdRule' | translate }}</md-hint>
</md-input-container>
This container has a div inside with class (mat-input-wrapper) which has a padding of padding-bottom: 1.296875em. 该容器内部有一个div类,其类别为(mat-input-wrapper),该类的padding-bottom:1.296875em填充。
How do I override this padding style of the container? 如何覆盖容器的这种填充样式?
PS : Adding class to the container and making the padding: 0px as important also doesnt work. PS:将类添加到容器中并进行填充:0px同样重要,这也不起作用。
Official Response from Angular about /deep/
or >>>
( Thanks @DeborahK ) Angular关于
/deep/
或>>>
官方回复( 感谢@DeborahK )
Support for the emulated /deep/ CSS Selector (the Shadow-Piercing descendant combinator aka >>>) has been deprecated to match browser implementations and Chrome's intent to remove.
已不再支持模拟的/ deep / CSS选择器(即“影子穿透”后代组合器,也称为>>>),以匹配浏览器实现和Chrome的删除意图。 ::ng-deep has been added to provide a temporary workaround for developers currently using this feature.
添加了:: ng-deep为当前正在使用此功能的开发人员提供临时解决方法。
From: http://angularjs.blogspot.co.uk/2017/07/angular-43-now-available.html 来自: http : //angularjs.blogspot.co.uk/2017/07/angular-43-now-available.html
Another related question 另一个相关的问题
Add a more specific style to the component - see CSS specificity 向组件添加更特定的样式- 请参阅CSS特定性
html html
<md-input-container id="forceStyle">
<input mdInput [placeholder]="'common.password' | translate" type="password" formControlName="password" (change)="onPasswordChange($event.target.value)" required validate-onBlur/>
<md-hint *ngIf="frmLoginInfo.controls.password.pristine" class="s-text-caption s-hint">{{ 'signup.pwdRule' | translate }}</md-hint>
</md-input-container>
css 的CSS
>>> #forceStyle .mat-input-wrapper {
padding-bottom: 0px;
}
You need the >>>
as explained here 您需要
>>>
作为解释这里
However /deep/
and >>>
are deprecated as explained here 然而
/deep/
和>>>
被弃用解释这里
Try this: 尝试这个:
<div class="box-model">
<md-input-container fxFlex="auto" class="custom-search-mdinput">
<input mdInput [placeholder]="'common.password' | translate" type="password" formControlName="password" (change)="onPasswordChange($event.target.value)" required validate-onBlur/>
<md-hint *ngIf="frmLoginInfo.controls.password.pristine" class="s-text-caption s-hint">{{ 'signup.pwdRule' | translate }}</md-hint>
</md-input-container>
</div>
@Component({
selector: "dashboard",
templateUrl: "dashboard.component.html",
styles: [`.box-model .mat-input-wrapper {
margin: 0px !important;
padding-bottom: 0px !important;
}`
],
HTML 的HTML
<div id="wrapper">
<md-input-container>
<input mdInput [placeholder]="'common.password' | translate" type="password" formControlName="password" (change)="onPasswordChange($event.target.value)" required validate-onBlur/>
<md-hint *ngIf="frmLoginInfo.controls.password.pristine" class="s-text-caption s-hint">{{ 'signup.pwdRule' | translate }}</md-hint>
</md-input-container>
</div>
CSS 的CSS
#wrapper .mat-input-wrapper{padding-bottom: 0px !important;}
Important .mat-input-wrapper
need to be a child of wrapper
- from your example I don't know where that class come from 重要
.mat-input-wrapper
必须是一个孩子wrapper
-从你的榜样,我不知道那个类来自
After your post update I think it should work the following: #forceStyle > .mat-input-wrapper{padding-bottom: 0 !important}
- should work even without the important
but just to be sure. 更新您的帖子后,我认为它应该可以以下工作:
#forceStyle > .mat-input-wrapper{padding-bottom: 0 !important}
-即使没有important
也可以工作,只是为了确保。
Make sure you clear cache and even relaunch the app because sometimes changes are not loaded 确保清除缓存,甚至重新启动应用程序,因为有时未加载更改
Use deep for styling 使用深层样式
/deep/ .mat-input-wrapper {
padding-bottom: 0px ;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.