进行了一些尝试和错误,但这就是我发现更改 ionic7 中离子输入的标签部分的方法:
CSS:
::ng-deep ion-input .label-text{
color: orange;
}
<ion-item>
<ion-input labelPlacement="stacked" value="[email protected]">
<div slot="label"> <ion-text color="danger"> Email (Required)</ion-text></div>
</ion-input>
</ion-item>
另外两个没有已弃用的
::ng-deep
选择器的选项:
ion-input.red label .label-text {
color: 'red';
}
<ion-item>
<ion-input labelPlacement="fixed" class="red"></ion-input>
</ion-item>
Ionic 文档中也提到了此选项。
您可以将组件样式表内的--color
变量设置为所需的颜色。
// my-component.styles.css
:host ion-input {
// change the text for all ion-input elements inside this component to red.
--color: red
}
或者将其包装在一个附加类中,以防您想要有多个选项:
// my-component.styles.css
:host ion-input.red {
// change the text for ion-input elements with classname red inside this component to red.
--color: red
}
<ion-input labelPlacement="fixed" class="red"></ion-input>