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%
猜你喜欢
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
