As per question, how can I change the color of the text inside ion-button? Here's the code for my button
<button ion-button block (click) = "submitForm()">Submit</button>
I've tried various methods like below
<button ion-button block (click) = "submitForm()"><sub ion-text color = "light">Submit</sub></button>
<button ion-button block (click) = "submitForm()" ion-text color = "light">Submit</button>
<button ion-button block (click) = "submitForm()"><span ion-text color = "light">Submit</span></button>
<button ion-button block (click) = "submitForm()" class= "font-white">Submit</button>
where in the last example above I put in .font-white{color: #fff !important;} inside app.scss
but nothing works.
Just replace the style attribute from button give class name and then in your app.scss but below code(assume u give class name as font-white)
.font-white
{
color : #fff !important;
}
Modify your component.html and component.scss file in following way,
<button ion-button block (click)="submitForm()" class="custom-button">Submit</button>
In your component.scss,
.custom-button{
color: #000;
}
This is working fine in ionic-4:-
<button ion-button block class="font-white">Submit</button>
In appcomponent.scss
.font-white {
color: #fff;
}
For Ionic-5:-
<ion-button class="font-white">Submit</ion-button>
in scss file
.font-white {
--color: #fff;
}
if you want white color only then do not create any of scss class
just write
<ion-button fill="clear" class="text-white" (click)="btnClickFN()">
save
</ion-button>
else if you want to give custom color then please make class in .scss
it will apply on all the tag where you wrote <ion-button></ion-button> tag
ion-button{
color: #00FF00; // green color
}
else you can give color only in specific one button then please create customclass like below in file of
.sccs
.btnColor{
color: #00FF00; // Green color
}
in .html file::
just put class inside <ion-button> tag and give name as u give in .scss file
<ion-button fill="clear" class="btnColor" (click)="btnClickFN()">
save
</ion-button>
Related
I'm using Ionic5 Angular and I would like to create a highlight around ion-avatar when the user clicked on it and will be disappeared if the user clicked on it again.
Users can click on each image (one at a time) and there will be a highlight around the image.
HTML:
<ion-card class="scrolling-wrapper">
<div class="item" *ngFor="let item of list">
<ion-avatar>
<img [src]= "source to image" >
</ion-avatar>
</div>
</ion-card>
SCSS:
.scrolling-wrapper {
white-space: nowrap;
overflow-x: scroll;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
.item {
display: inline-block;
margin: 4px;
}
}
You have to proceed like this:
Declare an empty variable (example: highlightedAvatar = "";)
Capture the id of the clicked item from the .html
If your variable has a value, you empty it, otherwise you assign the id
create the styles you want to add to the .css (e.g. brightness...)
Load the css class with a condition
You seriously need to provide some code so you can understand exactly the procedure
Edit:
HTML:
<ion-card class="scrolling-wrapper">
<div class="item" *ngFor="let item of list">
<ion-avatar [class.highlighted]="highlighted == item.id" (click)="selectAvatar(item.id)">
<img [src]= "source to image" >
</ion-avatar>
</div>
</ion-card>
TS:
export class AppComponent{
highlighted = "";
...
selectAvatar(id){
if (this.highlighted === "") {
this.highlighted = id;
} else {
this.highlighted = "";
}
}
SCSS:
.highlighted{
filter: brightness(120%);
}
Of course you can toy around with the css to style your way of highlighting
I need to change the background color of the selected radio input.
I have the following ion-radio list:
<ion-list radio-group [(ngModel)]="selectedRadio">
<ion-item *ngFor="let ing of pizzaIng; let i = index">
<ion-label>{{ing.name}}</ion-label>
<ion-radio [value]="ing.name"></ion-radio>
</ion-item>
</ion-list>
The only way it's working, is by overriding item-md class of ion-item into:
ion-item.item-md{
background-color: red;
}
But its changing all the radio options displayed. How can I only change the color of the selected one?
Here is a prepared stackblitz for it.
got this to work on my ionic 3 project and works in your demo. also just a heads up on using classes with 'md' at the end will only effect android.
.css
page-home {
.item-radio-checked{
background-color: #a0a;
}
}
I use the following code to allow me change the color of button when I click the button. It works fine. But when I try to add CSS to change the width and height of the buttons. The color change were working but the button size didn't change. Here is my code :
html code
<ion-content padding>
<ion-row>
<ion-col width-50 style="text-align: right" no-padding >
<button ion-button full no-margin class="bsize" (click)="addEvent('b1');" [ngStyle]="{'background-color': buttonColorb1}">button 1</button>
</ion-col>
<ion-col width-50 style="text-align: left" no-padding>
<button ion-button full no-margin class="bsize" (click)="addEvent('b2');" [ngStyle]="{'background-color': buttonColorb2}">button 2</button>
</ion-col>
</ion-row>
</ion-content>
scss code :
.bsize {
--width: 100px;
--height: 40px;
}
ts code :
export class TestButtonPage implements OnInit {
buttonColorb1: string = '#D3D3D3'; //Default Color
buttonColorb2: string = '#D3D3D3'; //Default Color
constructor() { }
addEvent(btn){
if (btn == "b1") {
this.buttonColorb1 = '#add8e6'; //desired Color
this.buttonColorb2 = '#D3D3D3'; //desired Color
}
else {
this.buttonColorb1 = '#add8e6'; //desired Color
this.buttonColorb2 = '#D3D3D3'; //desired Color
}
}
ngOnInit() {
this.buttonColorb1 = '#add8e6'; //desired Color
this.buttonColorb2 = '#D3D3D3'; //desired Color
}
}
Use below CSS,
.bsize {
width: 100px;
height: 40px;
}
StackBlitz Example
I am new in ionic and wants to learn it. my question is How to change nav bar color for all the pages in ionic 3.
I have been using following code
<ion-header>
<ion-navbar color="primary">
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Hello Ionic</ion-title>
</ion-navbar>
</ion-header>
Is there any way to change nav bar color for all the pages instead of manually doing <ion-navbar color="primary">
Add following line to variables.scss file to change the color globally.
$toolbar-background: #3D9BDD;
This can achieve different way i will show you 2 way
First way
In variables.scss file $colors portion add customColor
$colors: (
primary: #488aff,
secondary: #32db64,
danger: #f53d3d,
light: #f4f4f4,
dark: #222,
customColor:(
base: #00953B,
contrast: #ffffff
)
);
Here base is background color and contrast is text-color
And change in .html file
<ion-header>
<ion-navbar color="customColor">
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>Hello Ionic</ion-title>
</ion-navbar>
</ion-header>
Second way
override default color toolbar color
$toolbar-background: #00953B;
If anyone is looking for a solution using dynamic themes, it is possible to change the text color using css like this in Ionic 3:
.header .toolbar-title {
color: #fff !important;
}
In the Ionic app, I need to change the background color for my side menu to become red . By default , when I click or press on one item stable color become the background color but I need to become red .
see this
You can use sass to build your own custumized ionic.css
You can give custom css to set the background color like <ion-content class="dark">
Css
.dark {
background-color: red !important;
color: #ffffff;
}
Sample HTML
<ion-side-menu side="left">
<ion-header-bar class="bar bar-dark">
<h1 class="title">Left Menu</h1>
</ion-header-bar>
<ion-content class="dark">
<ion-list class="list">
<ion-item href="#/event/check-in">Check-in</ion-item>
<ion-item href="#/event/attendees">Attendees</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
You can check the full code/demo on the codpen which have proper comments also : http://codepen.io/mhartington/pen/qafgv
For the other reference you can check this also : http://pointdeveloper.com/ionic-change-side-menu-color/
Try overriding item.active.item-stable and item.activated.item-stable styles in your custom CSS.
Add below styles in your custom CSS:
.item.active.item-stable, .item.activated.item-stable, .item-complex.active .item-content.item-stable, .item-complex.activated .item-content.item-stable, .item .item-content.active.item-stable, .item .item-content.activated.item-stable{
border-color: #B81D22;
background-color: #B81D22;
}