如何在 ionic 4 中给 Alert Controller css?
how to give Alert Controller css in ionic 4?
我想在 ionic 中提供警报控制器样式4.these 是我的演示代码,
async presentalert() {
const alert = await this.alertCtrl.create({
header: ' DO YOU WANT TO CANCEL',
message: 'DO YOU WANT TO CANCEL',
cssClass: 'alertCancel',
mode: 'ios',
buttons: [
{
text: 'NO',
role: 'cancel',
cssClass: 'alertButton',
handler: () => {
console.log('Confirm Cancel');
}
}, {
text: 'YES',
cssClass: 'alertButton',
handler: () => {
console.log('Confirm Okay');
}
}
]
})
await alert.present();
}
我尝试在 global.scss
中应用 scss
.alertCancel{
--background: red;
}
.alertButton {
background-color: white !important;
}
我已经尝试了所有可能的方法在警报控制器中提供 css 但它不起作用所以请帮助我,我被困在这里。
--background
是组件 ion-alert
的一个 css 变量,因此在 variables.scss
中执行以下操作
ion-alert
{
--background: red !important;
}
供参考:
https://ionicframework.com/docs/theming/css-variables#ionic-variables
如果您希望使用定义的 cssClass 而不是组件 ion-alert 来设计您的提醒样式,那么将以下代码添加到您的 variables.scss
.alertCancel{
--background: red;
button.alertButton{
color: white;
}
}
结果
Since, ion-alert do not provide CSS Custom Properties to style alert buttons. I suggest you to use defined cssClass to style your alert rather than ion-alert when you want to style your alert buttons too.
我遇到了同样的问题,这对我有用,不需要使用“!重要”
在 variables.scss 我添加了这个:
@media (prefers-color-scheme: light){
body{
--ion-background-color: rgb(240, 248, 240);
}
ion-alert{
--ion-background-color: #ffffff;
}
}
这允许为应用程序的背景设置一个通用颜色,但会针对每个警报更改它(在本例中,在浅色主题上):)
我想在 ionic 中提供警报控制器样式4.these 是我的演示代码,
async presentalert() {
const alert = await this.alertCtrl.create({
header: ' DO YOU WANT TO CANCEL',
message: 'DO YOU WANT TO CANCEL',
cssClass: 'alertCancel',
mode: 'ios',
buttons: [
{
text: 'NO',
role: 'cancel',
cssClass: 'alertButton',
handler: () => {
console.log('Confirm Cancel');
}
}, {
text: 'YES',
cssClass: 'alertButton',
handler: () => {
console.log('Confirm Okay');
}
}
]
})
await alert.present();
}
我尝试在 global.scss
中应用 scss .alertCancel{
--background: red;
}
.alertButton {
background-color: white !important;
}
我已经尝试了所有可能的方法在警报控制器中提供 css 但它不起作用所以请帮助我,我被困在这里。
--background
是组件 ion-alert
的一个 css 变量,因此在 variables.scss
ion-alert
{
--background: red !important;
}
供参考:
https://ionicframework.com/docs/theming/css-variables#ionic-variables
如果您希望使用定义的 cssClass 而不是组件 ion-alert 来设计您的提醒样式,那么将以下代码添加到您的 variables.scss
.alertCancel{
--background: red;
button.alertButton{
color: white;
}
}
结果
Since, ion-alert do not provide CSS Custom Properties to style alert buttons. I suggest you to use defined cssClass to style your alert rather than ion-alert when you want to style your alert buttons too.
我遇到了同样的问题,这对我有用,不需要使用“!重要” 在 variables.scss 我添加了这个:
@media (prefers-color-scheme: light){
body{
--ion-background-color: rgb(240, 248, 240);
}
ion-alert{
--ion-background-color: #ffffff;
}
}
这允许为应用程序的背景设置一个通用颜色,但会针对每个警报更改它(在本例中,在浅色主题上):)