ionic-frameworkionic4shadow-domionic-viewionic-vue

Ionic 4 custom styling Shadow DOM


Been trying to change footer background but I cant get it right. I have a color for each tag but only the last tag is changed (blue - #0000ff) . How does one do styling in Ionic 4?

<template>
  <ion-footer>
    <ion-toolbar>
      <ion-title v-if="loggedIn">
        <a href="https://www.facebook.com/" target="_blank">
          <ion-icon name="logo-facebook"></ion-icon>
        </a>
        <a href="https://www.instagram.com/" target="_blank">
          <ion-icon name="logo-instagram"></ion-icon>
        </a>
      </ion-title>
    </ion-toolbar>
  </ion-footer>
</template>

<script>
export default {
  name: "pageFooter",
  computed: {
    loggedIn() {
      return this.$store.getters.loggedIn;
    }
  }
};
</script>

<style lang="scss">
ion-footer {
  background-color: #ff0000;
  ion-toolbar {
    background-color: #00FF00;
    ion-title {
      background-color: #0000ff;
      a {
        font-size: 25px;
        color: #000;
      }
    }
  }
}
</style>

enter image description here

It has something to do with "shadow dom" concept which I dont fully undersrtand yet . This DOM structure for the footer.

enter image description here


Solution

  • Ionic 4 uses web components, so the way to style components in Ionic 4 is to use the CSS variables that Ionic provides.

    In your case, set the --background property of the component:

    ion-footer {
      --background: #ff0000;
    }