有没有办法在mat-datepicker中垂直居中日期选择器?

huangapple go评论122阅读模式
英文:

Is there a way to center datepicker vertically in mat-datepicker?

问题

有两个状态:

状态 - 01:

有没有办法在mat-datepicker中垂直居中日期选择器?

状态 - 02:

有没有办法在mat-datepicker中垂直居中日期选择器?

在状态-01中,“选择日期”垂直居中。就像这样,我尝试将“选择日期”文本和所选日期垂直居中。不确定我漏掉了什么。请帮助我。

我的StackBlitz链接在这里

英文:

There are two states :

State - 01:

有没有办法在mat-datepicker中垂直居中日期选择器?

State - 02:

有没有办法在mat-datepicker中垂直居中日期选择器?

In state-01 , "Choose a date" is vertically centered . Like that , I'm trying to center "Choose a date" text and selected date vertically . Not sure what I'm missing . Please help me out .

My stackBlitz link is here

答案1

得分: 0

在你的情况下,当你需要为输入框设置样式时,angular-material提供了appearance="outline"属性,如果你想要使用,就像这样:

<mat-form-field appearance="outline">
    <mat-label>Outline form field</mat-label>
    <input matInput placeholder="Placeholder">
    <mat-icon matSuffix>sentiment_very_satisfied</mat-icon>
    <mat-hint>Hint</mat-hint>
</mat-form-field>

如果你想要像你的示例那样自定义样式,那么你需要进行一些样式设置,比如在具有float-label时给它添加padding,如下所示:

::ng-deep .mat-form-field.mat-form-field-should-float {
    padding-top: 20px;
}

原因:mat-input的正常行为是将标签浮动在一些负值上方,你可以将它的float设置为never,这样标签就不会上浮,欲了解更多,请参阅官方文档

英文:

In your case when you need to style input with box angular-material provide that input 'appearance="outline"` if you want to use, like this

&lt;mat-form-field appearance=&quot;outline&quot;&gt;
    &lt;mat-label&gt;Outline form field&lt;/mat-label&gt;
    &lt;input matInput placeholder=&quot;Placeholder&quot;&gt;
    &lt;mat-icon matSuffix&gt;sentiment_very_satisfied&lt;/mat-icon&gt;
    &lt;mat-hint&gt;Hint&lt;/mat-hint&gt;
  &lt;/mat-form-field&gt;

Else if you want to style that custom like in your example then you need a some styling like give it padding when it has float-label like below

::ng-deep .mat-form-field.mat-form-field-should-float {
    padding-top:20px;
}

> REASON: Normal behavior of mat-input is that it float the label
> above in some negative values, you can set that float to never so
> that label doesn't go above, for more you can read in its [OFFICIAL
> DOC]

(https://material.angular.io/components/input/overview)

huangapple
  • 本文由 发表于 2020年1月6日 14:56:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/59607888.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定