Change css in Ionic 4
我在将样式从Ionic 3迁移到Ionic 4时遇到问题,在我的一个视图中,我将背景配置为一种颜色,在某种形式下,我有3个离子项,这是我遇到的第一个问题有一个问题是,我修改了item-inner,使其没有边框并且不起作用,第二个是ion-toggle默认情况下采用了我视图的背景色,如果更改了它,则将其值设置为正确的checked
HTML:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <ion-header> </ion-header> <ion-content no-bounce> <ion-row class="img"> <img src="assets/imgs/logo.png" alt="Movistar"> </ion-row> <ion-row class="click"> Click! </ion-row> <form novalidate padding-horizontal margin-top> <ion-list padding-horizontal> <ion-item class="custom-item"> <ion-label fixed>Usuario</ion-label> <ion-input type="text" name="username" class="invalid" required></ion-input> </ion-item> <!--<ion-label padding-horizontal color="danger"> Campo requerido</ion-label>--> <ion-item class="custom-item" margin-top> <ion-label fixed>Contrase?±a</ion-label> <ion-icon slot="end" name="eye-off"></ion-icon> <ion-input type="password"></ion-input> </ion-item> <!--<ion-label padding-horizontal color="danger"> Campo requerido</ion-label>--> <ion-item id="remember"> <ion-label>Recordar credenciales?</ion-label> <ion-toggle color="success"></ion-toggle> </ion-item> <ion-button type="submit" expand="block" class="button-ingresar">Ingresar</ion-button> </ion-list> </form> </ion-content> |
Css:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | .toolbar-background { border: none !important; } .logo { .img { display: block; max-width: 500px; max-height: 98px; width: auto; height: auto; width: 100%; padding: 0px var(--padding); img { margin-top: 50px; display: block; max-width: 100%; height: auto; } } .click { display: inline-block; font-family: 'Custom'; color: white; font-size: 2.5rem; width: 100%; text-align: right; padding: 0px var(--padding); line-height: 4rem; } } form { .password-eye { position: relative; cursor: pointer; } #remember { background-color: transparent; color: white; margin-top: 8px; margin-bottom: 8px; .item-inner { border: none !important; } } ion-item { border: none !important; } .custom-item { color: white; border-radius: var(--border-radius); background-color: var(--custom-primary-contrast); border: none !important; .item-inner { border: none !important; } } .button { margin: 0; } } ion-content { --ion-background-color: var(--custom-primary); } .button-ingresar { --background: var(--custom-secondary) !important; } |
是的,从Ionic 3到Ionic 4需要一些修补。
我可以建议使用他们的文档,其中显示了新的css变量。
对于您的特定用例,我认为这两个css变量将解决此问题。
1 | --inner-border-width: 0; // The old .item-inner border fixer. |
和
1 | --background: var(--custom-primary-contrast); |
某些组件的边框半径也有相同的问题
1 | --border-radius: var(--border-radius); |
链接到用于ion-toggle
的css变量
链接到ion-button的css变量
希望有帮助!