Ionic apply different button styles - css

I want to apply different button styles in my view from my declared global button styles in theme/variables.scss
button_green{}
button_red{}
in my login.html
<button>Login</button> //should be green
<button>Logout</button> //should be red
How to assign different global styles to buttons without having individual component specific styles like
<button color='primary' font='xyz' size='n'>Login</button>
<button color='danger' hint='something'>Logout</button>
and more like this
<button style='button_green'>Login</button>
<button style='button_red'>Logout</button>

To use custom button style, You can follow my instruction below:
1- As you want to create global style, you need to add your style class in /theme/variables.scss as below:
Note: You need to add !important to overwrite default ionic style.
.button_green{
background-color: green !important;
}
.button_red{
background-color: red !important;
}
.button_blue{
background-color: blue !important;
}
.button_yellow{
background-color: yellow !important;
}
.button_pink{
background-color: pink !important;
}
.button_purple{
background-color: purple !important;
}
2- Then in *.html, you can call your css class like this:
<button ion-button class='button_green'>button_green</button>
<button ion-button class='button_red'>button_red</button>
<button ion-button class='button_blue'>button_blue</button>
<button ion-button class='button_yellow'>button_yellow</button>
<button ion-button class='button_pink'>button_pink</button>
<button ion-button class='button_purple'>button_purple</button>
3: As result you can see:
You can find full source code with this repository: Ionic Button Custom Collor.
I hope this will help you :)

If you want a custom button colors you can use below code -
1 - Declare below code in your CSS class
.font-size{
font-size : 2vw;
}
.red{
background-color: red ;
}
.blue{
background-color: blue ;
}
.green{
background-color: green ;
}
.yellow{
background-color: yellow ;
}
2.
<button ion-button class="font-size red">red</button>
<button ion-button class="font-size blue">blue</button>
<button ion-button class="font-size green">green</button>
<button ion-button class="font-size yellow">yellow</button>
Note - You can also use one class with another class

Related

Remove mat button focus from mat menu

How can I remove the black outline from my mat-menu-item?
Like this one.
<button mat-icon-button [matMenuTriggerFor]="menu4" style="margin-left:10px;" [disableRipple]="true">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu4="matMenu">
<button id="deactvateBtn" [disableRipple]="true" mat-menu-item>
<i [class]="!row['isActive'] ? 'fas fa-user-check' : 'fas fa-user-slash'"></i>
<span>{{ (!row['isActive'] ? 'Activate' : 'Deactivate') | titlecase }}</span>
</button>
</mat-menu>
I tried overriding the .mat-button-focus-overlay class with this:
.mat-button-focus-overlay {
background-color: whitesmoke!important;
}
But the outline is still there.
Other options I tried:
.mat-button-focus-overlay .cdk-program-focused {
background-color: transparent!important;
}
.mat-focus-indicator mat-menu-item ng-tns-c98-13 {
background-color: yellow!important;
}
Use ::ng-deep to re-style the mat buttons.
::ng-deep .mat-button-focus-overlay {
background-color: whitesmoke!important;
}
Use ::ng-deep to re-style the mat buttons.
::ng-deep .mat-button-focus-overlay {
border: none !important;
}
use this css, what you are trying to hide is not background but border color so you need to disable the border.
or try this css
::ng-deep .mat-button {
border: none !important;
}
I know it's late but in case someone else runs into this in the future, the class that I had to override was button:focus for .mat-menu-item and it was not the border but the outline that I had to get rid off, I added this to my css and it worked:
button.mat-menu-item:focus{
outline: none;
}
I know this is even later - but what worked for me today was
.mat-focus-indicator::before {
border: none;
}
in your global styles.css.
In chrome you can inspect the button and play around with the CSS. That's how I found it.
This is very very late but I think I found a solution that works for Angular 15 with all Angular Material components.
//In src/styles.scss
body {
--mat-focus-indicator-border-width: 0;
--mat-mdc-focus-indicator-border-width: 0;
}

How to override hover color of main nav bar button in bootstrap freelancer template?

I'm struggling with main navigation button menu hover color when working with official freelancer template:
https://github.com/BlackrockDigital/startbootstrap-freelancer
https://blackrockdigital.github.io/startbootstrap-freelancer/
Main button appears on narrower screens and should have the same hover color #128f76 like Send button from contact form on page bottom but it's blue #0062cc.
It seems that style responsible for this behavior is:
button.bg-primary:focus, button.bg-primary:hover
and is not overriden by styles specified in custom freelancer.css.
the style of the menu button on mobile devices is
a.bg-primary:focus, a.bg-primary:hover, button.bg-primary:focus, button.bg-primary:hover {
background-color: #0062cc !important;
}
this style is in the bootstrap.css file.
you should override this bg color by add this code to your CSS file
I was able to fix it by changing following files (making as little as possible changes)
index.html - remove bg_primary class, add btn btn-primary classes to Menu button
from
<button class="navbar-toggler navbar-toggler-right text-uppercase bg-primary text-white rounded"
to
<button class="navbar-toggler navbar-toggler-right text-uppercase btn btn-primary text-white rounded"
freelancer.css - remove btn class, add missing important! to btn-primary selectors
from
.btn {
border-width: 2px;
}
...
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
background-color: #128f76;
border-color: #128f76;
}
to
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
background-color: #128f76 !important;
border-color: #128f76 !important;
}

Bootstrap button color is not changing even by adding a css file and linking with html file?

I added a button code from bootstrap which goes like this:
<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#exampleModal">
Start Javascript
</button>
due to this code button color is red and i want to change that into orange for that i added a css file and linked that with html which goes like this:
.btn btn-danger {
background-color: orange;
}
but still color of button is red insted of orange
Correct CSS rule is
.btn.btn-danger {
background-color: orange;
}

Changing the color of checkmark inside ion-checkbox

I'm tring to change the color of the checkmark inside the ion-checkbox. The checkbox has a white background and the the checkmark is white Im tring to get the checkmark to be black not white. This is what I have so far
.checkbox-icon::before {
background-color: white !important;
}
.checkbox-icon::after {
color: black !important;
}
<ion-item ng-repeat="list in modal.item.modifier_lists | orderBy: 'ordinal'"
ng-if="list.modifier_options[0].name">
<div ng-if="list.modifier_options.length === 1"
class="row">
<div class="col">
<ion-checkbox ng-model="list.modifier_options[0].selected"
ng-checked="list.modifier_options[0].selected"
class="button-orange checkbox-stable">
<span class="pull-right">{{list.modifier_options[0].name}}</span>
</ion-checkbox>
</div>
</div>
</ion-item>
Some of the css- properties you can use to change the coloring of the <ion-checkbox> are
--checkmark-color: black;
--background-checked: white;
--border-color: black;
--border-color-checked: black;
You can find more information in the ion-checkbox documentation
I'm pretty sure you actually have to use border-color to adjust the checkmark color
So to clarify here is what you could do:
Inside your <ion-checkbox> add a custom class of your own custom-checkbox and then for that class do whats below:
.custom-checkbox .checkbox-icon:after {
border-color: //whatever you like it to be
}
That will change the color of the check mark when it is checked.

make btn color to btn-info in toggled navbar

I want btn in navbar (which appeared only toggled) get btn-info color.
I add a btn-info class,
btn's text color changed to white
and btn color was unchanged.
I used default bootstrap 3 css.
bootply - click mobile view
<a class="btn btn-info navbar-toggle" value="Page" href="javascript:win_memo('', '<?=$member[mb_id]?>', '<?=$_SERVER[SERVER_NAME]?>');" onfocus="this.blur()">
<i class="glyphicon glyphicon-envelope"><sup style="margin-left:3px;"><?=$member[mb_memo_unread]?></sup></i>
</a>
you need to use ( !important ) for your btn-info property value, because the (.btn-info)
is overridden by the (.navbar-toggle) class value, so the solution is to add this code to your custome.css file or any file that you use to override the main bootstrap.css file.
code:
.btn-info {
color: #fff;
background-color: #5bc0de !important;
border-color: #46b8da !important;
}
hope this will help you.
Ahmed Na's Answer works well. Great idea.
I add a class btn-info-navbar.
.btn-info-navbar {
color: #fff;
background-color: #5bc0de !important;
border-color: #46b8da !important;
}
and add btn-info-navbar.
<a class="btn btn-info btn-info-navbar navbar-toggle" value="Page" href="javascript:win_memo('', '<?=$member[mb_id]?>', '<?=$_SERVER[SERVER_NAME]?>');" onfocus="this.blur()">
<i class="glyphicon glyphicon-envelope"><sup style="margin-left:3px;"><?=$member[mb_memo_unread]?></sup></i>
</a>

Resources