简体   繁体   中英

Ionic Vue: How do I change the text color of a selected option?

I have a simple ionic select component with vue:

<template>
  <ion-item>
    <ion-label position="floating">Select</ion-label>
    <ion-select>
      <ion-select-option value="brown">Brown</ion-select-option>
      <ion-select-option value="blonde">Blonde</ion-select-option>
      <ion-select-option value="black">Black</ion-select-option>
      <ion-select-option value="red">Red</ion-select-option>
    </ion-select>
  </ion-item>
</template>

<script>
import { IonItem, IonLabel, IonSelect, IonSelectOption } from '@ionic/vue';

export default{
  components: { IonItem, IonLabel, IonSelect, IonSelectOption },
};
</script>

Once the user selected an option, I want to colour it respectively: 在此处输入图像描述

Unfortunatelly, the docs only reveal to me, how the colour the select option within the select dropdown ( here ).

To colour the selected option, I tried things like

<ion-select-option value="brown"><span style="color:brown">Brown</span></ion-select-option>

or

<ion-select-option value="brown" style="color:brown">Brown</ion-select-option>

How do I colour it in brown?

Ionic 5

You can use CSS Shadow Parts for that.
For the ion-select component, the exposed parts are icon , placeholder and text .

ion-select::part(text) {
  color: brown;
}

Unfortunately, I don't know to achieve that with earlier versions of Ionic.
It might work with latest versions of Ionic 4 though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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