简体   繁体   English

ionic5 设置背景颜色

[英]ionic5 set background color

I have created a few custom colors and would like to set the background of a ion-col cell.我创建了一些自定义 colors 并想设置ion-col单元格的背景。 But how?但是怎么做? My colors work for buttons for instance:例如,我的 colors 适用于按钮:

<ion-button color="custom-blue" ... >...</ion-col>

but

<ion-col color="custom-blue" ... >...</ion-col>

fails.失败。 Same with background-color .background-color相同。 Can I set ion-col colors at all or to I have to paste a ion-item into it?我可以完全设置ion-col colors 还是必须将ion-item粘贴到其中?

Use background-color CSS property.使用background-color CSS 属性。 color attribute does not exist for ion-col ion-col不存在color属性

However, you won't be able to access your custom color directly inside SCSS file.但是,您将无法直接在 SCSS 文件中访问您的自定义颜色。 Use this to apply background to all ion-col :使用它为所有ion-col应用背景:

ion-col{
background-color:var(--ion-color-custom-blue);
}

Try this.尝试这个。 Add your --ion-color-custom-blue to varibles.scss将您的--ion-color-custom-blue添加到 varibles.scss

在此处输入图像描述

In your html page在您的 html 页面中

<ion-col class="color-class">

In your scss在你的 scss

.color-class {
  background-color: var(--ion-color-custom-blue);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM