I try to change color of the ion-title in ionic 2.
I have this following code:
<ion-header>
<ion-navbar>
<ion-title primary>Title</ion-title>
</ion-navbar>
</ion-header>
The color of the ion-title
don't change. I try several things like:
<ion-title color="primary">Title</ion-title>
<ion-title>
<p primary>Title</p>
</ion-title>
With the second I have the title in the right color, but the header is big. So I add this in the variables.scss:
$toolbar-ios-height: 5rem; // ios
$toolbar-md-height: 5rem; // android
But nothing change.Does anyone have a solution? Or do I have to use the p
or h
tag to change the color?
The text component is a simple component that can be used to style the text color of any element. The ion-text element should wrap the element in order to change the text color of that element.
The fastest way to change the theme of your Ionic app is to set a new value for primary , since Ionic uses the primary color by default to style most components. Colors can be removed from the map if they aren't being used, but primary should not be removed.
html" file in the src folder. You would see the "title" html tag. Change it there and it would reflect.
Remove the color="..."
from the ion-title
element and use this sass variables in your variables.scss
file:
$toolbar-md-title-text-color: #777;
$toolbar-ios-title-text-color: #777;
$toolbar-wp-title-text-color: #777;
If you want to use one the colors included in the named color variables
$colors: (
primary: #488aff,
secondary: #32db64,
danger: #f53d3d,
light: #f4f4f4,
dark: #222,
...
custom: #777
);
You can do it by using map-get
like this:
$toolbar-md-title-text-color: map-get($colors, custom);
$toolbar-ios-title-text-color: map-get($colors, custom);
$toolbar-wp-title-text-color: map-get($colors, custom);
Note:
Setting the color with just the color
attribute has been deprecated since the 3.0.0 version of Ionic more info.
Update:
[...] all the element on the navbar change color, Can we just change the ion-title? Or have a second variable to change the other elements?
You can add this style rule in the app.scss
file (to make it global) and it will only change the title and nothing else:
.toolbar-title.toolbar-title-md,
.toolbar-title.toolbar-title-ios,
.toolbar-title.toolbar-title-wp { color: map-get($colors, custom); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With