cssvue.jsionic-frameworkionic-vue

why i can not change background color of ion-header with css class selector in my ionic vue component?


I have started learning ionic vue. I am trying to use css with ionic components. So I added style to the same file

<style scoped>
    .abc {
        background-color: blue;
    }
</style>

And tried to access it with

<ion-content class ="abc">
    <ion-header>
        <ion-toolbar>
            <ion-title size="large">My Navigation Bar</ion-title>
        </ion-toolbar>
    </ion-header>
</ion-content>

But it is not working. How do i do this? Here is my full code

<template>
  <ion-page>
    <ion-content class ="abc">
        <ion-header>
          <ion-toolbar>
            <ion-title size="large">My Navigation Bar</ion-title>
          </ion-toolbar>
        </ion-header>
    </ion-content>
  </ion-page>
</template>

<script>
    import { IonContent, IonPage } from "@ionic/vue";
    import { defineComponent } from "vue";

    export default defineComponent({
        name: "Home",
        components: {
            IonContent,
            IonPage
        },
    });
</script>

<style scoped>
    .abc {
        background-color: blue;
    }
</style>

Solution

  • I had to change code as bellow

    <style scoped>
        .abc {
            --background: blue;
        }
    </style>
    

    and select the css class from toolbar

    <ion-toolbar class="abc">