Setting angular material#39;s textarea to 50% of component(将角度材质的纹理区域设置为组件的50%)
本文介绍了将角度材质的纹理区域设置为组件的50%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个角度为6的应用程序(我计划将其迁移到NG7),并且在其中一个组件中需要添加两个元素,ng材质的textarea和我的定制组件。每一个都应该占可用高度的50%。我对文本区域有一个问题,因为生成的mat-form-field-wrapper只占用它所需的空间,并且我无法在该元素中实现我的目标(我不想使用任何::Ng-Deep解决方案,因为不推荐这样做)
以下是我到目前为止所做的工作(当然是示例):
<form [formGroup]="myGroup" fxLayout="column" fxLayoutAlign="center stretch" fxFlex="1 1 100%">
<mat-form-field fxFlex="1 1 100%" fxLayout="column" fxLayoutAlign="start stretch">
<textarea matInput formControlName="myControl" fxFlex="1 1 100%"></textarea>
</mat-form-field>
</form>
<my-custom-component *ngIf="somevariable" [variable]="somevariable"></my-custom-component>
推荐答案
您需要覆盖全局样式表中的样式,以替代使用Deep。由于表单域元素的布局方式和变量填充等原因,我不确定您是否能在所有条件下完美地工作,但这里是一个起点:
<form [formGroup]="myGroup" style="display: flex; flex-direction: column; height: 50%;">
<mat-form-field class="stretch-height">
<textarea matInput formControlName="myControl"></textarea>
</mat-form-field>
</form>
<my-custom-component style="height: 50%" *ngIf="somevariable" [variable]="somevariable"></my-custom-component>
全局css:
.mat-form-field.stretch-height,
.mat-form-field.stretch-height .mat-form-field-flex,
.mat-form-field.stretch-height textarea {
height: 100%;
}
.mat-form-field.stretch-height .mat-form-field-wrapper {
height: calc(100% - 1.34375em);
}
.mat-form-field.stretch-height .mat-form-field-infix {
height: calc(100% - 1.34375em - 2px);
}
父容器的高度应为100%或您希望的高度,这一点很重要。
这是StackBlitz上的演示。
这篇关于将角度材质的纹理区域设置为组件的50%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:将角度材质的纹理区域设置为组件的50%


基础教程推荐
猜你喜欢
- 在for循环中使用setTimeout 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 我什么时候应该在导入时使用方括号 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 动态更新多个选择框 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01