Hello my beloved community,
Using angular with angular material.
With the default configuration when you open up a material dialog, it darkens the background a bit. Now I would like it to be a blurred background instead. I tried playing around with the css styles but I could not get the background of the window to change (couldn't get the right selector inside of component template).
I went through the documentation but there is nothing there. I can play a little bit more with the styles since I am sure there is probably some tricky way but considering the darkening effect is already there out of the box I would assume there should be a theming feature available out of the box as well. What you think?
I guess you've missed the property MatDialogConfig - backdropClass in the docs.
Check this StackBlitz DEMO for a simple example
From this DEMO:
dialog-overview-example.ts:
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: {name: this.name, animal: this.animal},
backdropClass: 'backdropBackground' // This is the "wanted" line
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
styles.css:
.backdropBackground {
/* your css needs */
}
You can achieve a nice effect by combining opacity and blur. Do like this:
Add backdropClass to your dialog-options:
backdropClass: "bdrop"
And these rules to your stylesheet:
.bdrop {
background-color: #bbbbbbf2;
backdrop-filter: blur(4px);
}
Demo: https://angular-blurred-dialog-backdrop-zdyvpc.stackblitz.io/
The given answer by #benshabatnoam is absolutely correct, but the documentation also has another option to disable the backdrop altogether.
hasBackdrop
Here is an example:
https://stackblitz.com/edit/angular-ei9hdv
Also you can just overide class .mat-dialog-container {} in your styles.scss
.mat-dialog-container {
box-shadow: 0px 11px 15px -7px rgb(0 0 0 / 20%), 0px 24px 38px 3px rgb(0 0 0 / 14%), 0px 9px 46px 8px rgb(0 0 0 / 12%);
background: #fff;
color: black;
}
const dialogConfig = new MatDialogConfig();**strong text**
dialogConfig.id="dialog"
this.dialog.open(CreatOrderComponent,dialogConfig)
// you can give it an ID then you can use that id to style it
I am attempting to override the default max-width of the snackbar component in Angular Material.
The CSS applied by Angular Material is shown below:
.mat-snack-bar-container {
border-radius: 2px;
box-sizing: border-box;
display: block;
margin: 24px;
max-width: 568px;
min-width: 288px;
padding: 14px 24px;
transform: translateY(100%) translateY(24px);
}
I have tried overriding using the same style in my style.css file but this style is overridden by the default style.
.mat-snack-bar-container {
max-width: 800px;
}
I have found an answer to a similar question but I know the answer to that question is now deprecated (/deep/ is deprecated).
Is there a best practices solution to this?
To do this properly, you need to set the View Encapsulation to None on your component:
#Component({
templateUrl: './my.component.html' ,
styleUrls: ['./my.component.css'],
encapsulation: ViewEncapsulation.None,
})
Then in your component css you can just do this:
.mat-snack-bar-container {
max-width: 800px;
}
From the official docs:
View Encapsulation = None means that Angular does no view
encapsulation. Angular adds the CSS to the global styles. The scoping
rules, isolations, and protections discussed earlier don't apply. This
is essentially the same as pasting the component's styles into the
HTML.
Put css in your styles.scss or styles.css
.snackbar {
max-width: 90% !important;
margin-left: auto !important; // center align from left
margin-right: auto !important; // center align from right
margin-bottom: 1rem !important;
padding: 10px !important; // spacing between the text and boundary
background-color: green;
color: white;
.mat-button-wrapper {
color: black !important; // action text color
}
}
Note: make sure you have set !important with every style, without it, style wouldn't work.
in component.ts
this.snackbar.open(this.resMsg.message, 'OK', {
panelClass: 'snackbar'
})
Verified for #angular/material v7.0.x:
CSS !important modifier does the trick.
Put this is src/styles.scss (the app's global css):
.mat-snack-bar-container {
max-width: 100% !important;
}
Also we tweak its font:
/* Overrides SnackBar CSS in Material Design's .mat-simple-snackbar class */
/* Original sizes: font: 24px, height: 47.952px */
.mat-simple-snackbar {
display: flex;
font-size: 28px !important; // 28px is double, 42px for triple
min-height: 70px !important; // 70px for double, 90px for triple
align-items: center !important;
justify-content: center !important;
}
As of June 30, 2019, using Angular Material 8.0.1 with Angular 8.0.3, the following SCSS and typescript seems to work for overriding the color of the action button in an Angular Material snackbar *without using !important *:
styles.scss (not the extremely long duration, which allowed me to inspect the styling before it disappeared):
$snackBarTextColor: white;
$snackBarBackgroundNormal: #087a51;
$snackBarActionColor: lightgray;
.snackBarInfo {
background-color: $snackBarBackgroundNormal;
color: $snackBarTextColor;
}
.mat-simple-snackbar > span {
font-weight: bold;
}
.mat-simple-snackbar-action {
.mat-button {
.mat-button-wrapper {
color: $snackBarActionColor;
}
}
}
app.module.ts:
import { MAT_SNACK_BAR_DEFAULT_OPTIONS } from '#angular/material/snack-bar';
providers: [
{
provide: MAT_SNACK_BAR_DEFAULT_OPTIONS,
useValue: {
duration: 41000,
horizontalPosition: 'center',
verticalPosition: 'bottom',
panelClass: 'snackBarInfo'
}
}
]
I remember working in a project with web-designers, and they had a money-jar, where devs had to put a coin in if they used the !important statement. ;)
The other solutions did not work for me, unless i set the .cdk-overlay-pane (using material 11):
.cdk-overlay-pane {
width: 100%;
}
.mat-snack-bar-container {
max-width: 100%;
width: 100%;
}
Not sure when Material introduced this (must be a new thing judging by all the answers to this thread), but you can now override the mat-snack-bar-container's styles by passing a parameter in the _snackBar.open(), like this:
component.ts
openSnackBar(message: string, action: string) {
this._snackBar.open(message, action {
panelClass: 'my-custom-container-class',
});
}
component.scss
::ng-deep .my-custom-container-class{
max-width: 100% !important;
min-width: 0% !important;
min-height: 0 !important;
padding: 0 !important;
margin: 32px !important;
box-shadow: none;
}
I'm afraid you still have to use the ng-deep and the !importants; but at least you no longer need to do ViewEncapsulation None.
The way to go.
encapsulation: ViewEncapsulation.None
Here is a stackblick to demonstrate
Angular 10 and without special tricks:
use panelClass when opening the snackbar, for example:
this.snackBar.open("VeryLongTextWithoutThePossibilityOfBreakingAutomatically", "X", {
duration: 0,
panelClass: 'notif-error'
});
duration: 0 is only for debugging.
write this into your style.css
.notif-error {
background-color: red;
}
.mat-snack-bar-container.notif-error {
max-width: 100%;
}
Now because of css-specificity, this will be the most specific rule.
Beware that there should not be space between .mat-snack-bar-container and .notif-error.
This rule will apply to elements which has both the .mat-snack-bar-container and .notif-error classes.
This also works when your .notif-error class is empty.
Using vw works for me,on both bigger and small screen size
.mat-snack-bar-container {
margin-right: auto !important;
margin-left: auto !important;
width: 80vw !important;
max-width: 100vw !important;
}
FYI Starting with Angular Material v15 with the migradtion to MDC, the class .mat-snack-bar-container has been renamed to
.mat-mdc-snack-bar-container
I also had to use some of the new inner MDC snackbar classes to properly recolor the snackbar starting in v15:
SCSS:
// Classname used in the MatSnackBarConfig obj of MatSnackBar.open():
// panelClass: ['my-snackbar-class']
my-snackbar-class.mat-mdc-snack-bar-container {
.mdc-snackbar__surface {
// Background color of entire snackbar:
background-color: red;
.mdc-snackbar__label {
// Color of snackbar text:
color: white;
}
button {
// Color of snackbar button text:
color: white !important;
}
}
}
I need your advices. (Sorry for my eng. I hope than you'll understand me)
1) I want to create custom TabWidget and use QSS. Now it's look like this:
I want fill background under tabs (I accept property called autoFillBackground). It's need look like this:
2) When I start drag and drop tab this tab is filled with white color. And when I drop the tab this tab set custom qss.
I want to change the style when I drag and drop the tab.
Thx
(I was reading qss manual)
some code
QTabWidget::tab-bar {
background-color: black;
}
QTabBar::tab {
background-color: #4094da;
border-color:white;
font: bold 12px 'Arial';
color: white;
height:60px;
}
QTabBar::tab:!selected {
background-color: #9E9E9E;
color: white;
}
QTabBar::close-button {
background-position: center;
background-image: url(":/Appearance/close_chat_item");
}
QTabWidget::pane {
position: absolute;
}
QTabBar::tab:selected {
border-color:#4094da;
background-color: #4094da;
color: white;
}
The QTabWidget does not paint the background, you need to set the background of the parent widget of the QTabWidget.
As I understand, you willing the background color to change in any drag & drop situation(or it is my assumption). If it's like I understand, you should define hover option on your qss. For more info on Qt documentation.
Example code:
QTabBar::tab:selected, QTabBar::tab:hover {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #fafafa, stop: 0.4 #f4f4f4,
stop: 0.5 #e7e7e7, stop: 1.0 #fafafa);
}
Your priority should be forcing to cost on qss, logic structure consider to second plan or you can use for some kind of workaround.
Is there a way to change all .btn properties in Bootstrap? I have tried below ones, but still sometimes it shows the default blue color (say after clicking and removing the mouse etc). How can I change the entire theme altogether?
.btn-primary, .btn-primary:hover, .btn-primary:active, .btn-primary:visited {
background-color: #8064A2;
}
If you want to override any default properties in Bootstrap you have to make the properties as important.
.btn-primary, .btn-primary:hover, .btn-primary:active, .btn-primary:visited {
background-color: #8064A2 !important;
}
I hope this works for you.
2022 Update for Bootstrap 5
Bootstrap 5 has the same button-variant and button-outline-variant SASS mixins which can be used to customize the button color after bootstrap is imported...
/* import the Bootstrap */
#import "bootstrap";
/* ------- customize primary button color -------- */
$mynewcolor:#77cccc;
.btn-primary {
#include button-variant($mynewcolor, darken($mynewcolor, 7.5%), darken($mynewcolor, 10%), lighten($mynewcolor,5%), lighten($mynewcolor, 10%), darken($mynewcolor,30%));
}
.btn-outline-primary {
#include button-outline-variant($mynewcolor, #222222, lighten($mynewcolor,5%), $mynewcolor);
}
https://codeply.com/p/UNvB5hRsfF
2019 Update for Bootstrap 4
Now that Bootstrap 4 uses SASS, you can easily change the primary button color using the button-variant mixins:
$mynewcolor:#77cccc;
.btn-primary {
#include button-variant($mynewcolor, darken($mynewcolor, 7.5%), darken($mynewcolor, 10%), lighten($mynewcolor,5%), lighten($mynewcolor, 10%), darken($mynewcolor,30%));
}
.btn-outline-primary {
#include button-outline-variant($mynewcolor, #222222, lighten($mynewcolor,5%), $mynewcolor);
}
https://codeply.com/p/JnV3xDDiaH (SASS demo)
This SASS compiles into the following CSS...
.btn-primary {
color: #212529;
background-color: #7cc;
border-color: #5bc2c2
}
.btn-primary:hover {
color: #212529;
background-color: #52bebe;
border-color: #8ad3d3
}
.btn-primary:focus,
.btn-primary.focus {
box-shadow: 0 0 0 .2rem rgba(91, 194, 194, 0.5)
}
.btn-primary.disabled,
.btn-primary:disabled {
color: #212529;
background-color: #7cc;
border-color: #5bc2c2
}
.btn-primary:not(:disabled):not(.disabled):active,
.btn-primary:not(:disabled):not(.disabled).active,
.show>.btn-primary.dropdown-toggle {
color: #212529;
background-color: #9cdada;
border-color: #2e7c7c
}
.btn-primary:not(:disabled):not(.disabled):active:focus,
.btn-primary:not(:disabled):not(.disabled).active:focus,
.show>.btn-primary.dropdown-toggle:focus {
box-shadow: 0 0 0 .2rem rgba(91, 194, 194, 0.5)
}
.btn-outline-primary {
color: #7cc;
background-color: transparent;
background-image: none;
border-color: #7cc
}
.btn-outline-primary:hover {
color: #222;
background-color: #8ad3d3;
border-color: #7cc
}
.btn-outline-primary:focus,
.btn-outline-primary.focus {
box-shadow: 0 0 0 .2rem rgba(119, 204, 204, 0.5)
}
.btn-outline-primary.disabled,
.btn-outline-primary:disabled {
color: #7cc;
background-color: transparent
}
.btn-outline-primary:not(:disabled):not(.disabled):active,
.btn-outline-primary:not(:disabled):not(.disabled).active,
.show>.btn-outline-primary.dropdown-toggle {
color: #212529;
background-color: #8ad3d3;
border-color: #7cc
}
.btn-outline-primary:not(:disabled):not(.disabled):active:focus,
.btn-outline-primary:not(:disabled):not(.disabled).active:focus,
.show>.btn-outline-primary.dropdown-toggle:focus {
box-shadow: 0 0 0 .2rem rgba(119, 204, 204, 0.5)
}
https://codeply.com/go/lD3tUE01lo (CSS demo)
To change the primary color for all classes see: Customizing Bootstrap CSS template and How to change the bootstrap primary color?
The easiest way to see which properties you need to override is to take a look at Bootstrap's source code, specifically the .button-variant mixin defined in mixins/buttons.less. You still need to override quite a lot of properties to get rid of all of the .btn-primary styling (e.g. :focus, disabled, usage in dropdowns etc).
A better way might be to:
Create your own customized version of Bootstrap using Bootstrap's online customization tool
Manually create your own color class, e.g. .btn-whatever
Use a LESS compiler and use the .button-variant mixin to create your own color class, e.g. .btn-whatever
I guess you forgot .btn-primary:focus property and comma after .btn-primaryYou also can use less and redefine some colors in variables.less fileWith this in mind your code will be look like this:
.btn-primary,
.btn-primary:hover,
.btn-primary:active,
.btn-primary:visited,
.btn-primary:focus {
background-color: #8064A2;
border-color: #8064A2;
}
Just create your own button on:
http://blog.koalite.com/bbg/
add the CSS at the end off your boottrap.min.css
Cheers
Remove the button color class like "btn-success" and put a custom class like "btn-custom" and write css for that class. That simply works for me.
HTML :
<button class="btn btn-block login " type="submit">Sign In</button>
CSS:
.login {
background-color: #0057fc;
color: white;
}
The simplest way is to:
intercept every button state
add !important to override the states
.btn-primary:hover,
.btn-primary:active,
.btn-primary:visited,
.btn-primary:focus {
background-color: black !important;
border-color: black !important;
}
OR the more practical UI way is to make the hover state of the button darker than the original state. Just use the CSS snippet below:
.btn-primary {
background-color: Blue !important;
border-color: Blue !important;
}
.btn-primary:hover,
.btn-primary:active,
.btn-primary:visited,
.btn-primary:focus {
background-color: DarkBlue !important;
border-color: DarkBlue !important;
}
You have missed one style ".btn-primary:active:focus" which causes that still during btn click default bootstrap color show up for a second.
This works in my code:
.btn-primary, .btn-primary:hover, .btn-primary:active, .btn-primary:visited, .btn-primary:focus, .btn-primary:active:focus {
background-color: #8064A2;}
Here's my flavor without the loss of hover. I personally like it better than the standard bootstrap transitioning.
.btn-primary,
.btn-primary:active,
.btn-primary:visited {
background-color: #8064A2 !important;
}
.btn-primary:hover {
background-color: #594671 !important;
transition: all 1s ease;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<button class="btn btn-primary">Hover me!</button>
I had run into the similar problem recently, and managed to fix it with adding classes
body .btn-primary {
background-color: #7bc143;
border-color: #7bc143;
color: #FFF; }
body .btn-primary:hover, body .btn-primary:focus {
border-color: #6fb03a;
background-color: #6fb03a;
color: #FFF; }
body .btn-primary:active, body .btn-primary:visited, body .btn-primary:active:focus, body .btn-primary:active:hover {
border-color: #639d34;
background-color: #639d34;
color: #FFF; }
Also pay attention to [disabled] and [disabled]:hover, if this class is used on input[type=submit]. Like this:
body .btn-primary[disabled], body .btn-primary[disabled]:hover {
background-color: #7bc143;
border-color: #7bc143; }
Adding a step-by-step guide to #Codeply-er's answer above for SASS/SCSS newbies like me.
Save btnCustom.scss.
/* import the necessary Bootstrap files */
#import 'bootstrap';
/* Define color */
$mynewcolor:#77cccc;
.btn-custom {
#include button-variant($mynewcolor, darken($mynewcolor, 7.5%), darken($mynewcolor, 10%), lighten($mynewcolor,5%), lighten($mynewcolor, 10%), darken($mynewcolor,30%));
}
.btn-outline-custom {
#include button-outline-variant($mynewcolor, #222222, lighten($mynewcolor,5%), $mynewcolor);
}
Download a SASS compiler such as Koala so that SCSS file above can be compiled to CSS.
Clone the Bootstrap github repo because the compiler needs the button-variant mixins somewhere.
Explicitly import bootstrap functions by creating a _bootstrap.scss file as below. This will allow the compiler to access the Bootstrap functions and variables.
#import "bootstrap/scss/functions";
#import "bootstrap/scss/variables";
#import "bootstrap/scss/mixins";
#import "bootstrap/scss/root";
#import "bootstrap/scss/reboot";
#import "bootstrap/scss/type";
#import "bootstrap/scss/images";
#import "bootstrap/scss/grid";
#import "bootstrap/scss/tables";
#import "bootstrap/scss/forms";
#import "bootstrap/scss/buttons";
#import "bootstrap/scss/utilities";
Compile btnCustom.scss with the previously downloaded compiler to css.
A lot of complex and lengthy CSS here when all you need is this if you want to cover the whole button with one color including the button border:
.btn-primary, .btn-primary:hover, .btn-primary:active, .btn-primary:visited {
background-color: #D64B8A !important;
border-color: #D64B8A !important;
}
You can add custom colors using bootstrap theming in your config file for example variables.scss and make sure you import that file before bootstrap when compiling.
$theme-colors: (
"whatever": #900
);
Now you can do .btn-whatever
I think using !important is not a very wise option. It may cause for many other issues specially when making the site responsive. So, my understanding is that, the best way to do this to use custom button CSS class with .btn bootstrap class. .btn is the base style class for bootstrap button. So, keep that as the layout, we can change other styles using our custom css class.
One more extra thing I want to mention here. Some people are trying to remove blue outline from the buttons. It's not a good idea because that accessibility issue when using keyboard. Change it's color using outline-color: instead.
I am not the OP of this answer but it helped me so:
I wanted to change the color of the next/previous buttons of the bootstrap carousel on my homepage.
Solution:
Copy the selector names from bootstrap.css and move them to your own style.css (with your own prefrences..) :
.carousel-control-prev-icon,
.carousel-control-next-icon {
height: 100px;
width: 100px;
outline: black;
background-size: 100%, 100%;
border-radius: 50%;
border: 1px solid black;
background-image: none;
}
.carousel-control-next-icon:after
{
content: '>';
font-size: 55px;
color: red;
}
.carousel-control-prev-icon:after {
content: '<';
font-size: 55px;
color: red;
}
Here is my participation for the "outline" button:
Replace #8e5b5b with your color and #b3a7a7 by your color but usually more bright.
.btn-outline-custom{
color: #8e5b5b;
border-color: #8e5b5b;
}
.btn-outline-custom:focus{
box-shadow: 0 0 0 0.2rem #b3a7a7;
-webkit-box-shadow: 0 0 0 0.2rem #b3a7a7;
outline: 0;
}
.btn-outline-custom:hover,
.btn-outline-custom:active{
color: #fff;
background-color: #8e5b5b;
border-color: #8e5b5b;
}
As of Bootstrap 5, the right way to do this is to simply override the $primary theme colour:
Simply add the following to your Bootstrap overrides file (ie: could be named 'Core.scss' for example:
//
// Bootstrap
//
// overrides
$primary: /*new colour*/orange;
Here is the official docs: https://getbootstrap.com/docs/5.0/customize/sass/#modify-map
While digging through mixins.less file of bootstrap 3 I found the following:
// CSS image replacement
//
// Heads up! v3 launched with with only `.hide-text()`, but per our pattern for
// mixins being reused as classes with the same name, this doesn't hold up. As
// of v3.0.1 we have added `.text-hide()` and deprecated `.hide-text()`. Note
// that we cannot chain the mixins together in Less, so they are repeated.
//
// Source: https://github.com/h5bp/html5-boilerplate/commit/aa0396eae757
// Deprecated as of v3.0.1 (will be removed in v4)
.hide-text() {
font: ~"0/0" a;
color: transparent;
text-shadow: none;
background-color: transparent;
border: 0;
}
// New mixin to use as of v3.0.1
.text-hide() {
font: ~"0/0" a;
color: transparent;
text-shadow: none;
background-color: transparent;
border: 0;
}
Has anyone been using this? Where do I specify the image that I want to replace the text? Am I right to assume that all this does is to hide text and not replacing it with an image?
Yes, this does not include an image, it only hides text. You will need to do your own image replacement, perhaps in a custom CSS rule:
.my-image-replacement {
background-image:url('myImage.jpg');
.text-hide();
}
I use the following for convenience:
.image-replacement( #url, #width, #height ) {
display: block;
width: #width;
height: #height;
background: url(#url) no-repeat left top;
.text-hide();
}
.logo {
.image-replacement( "images/logo.png", 100px, 50px );
}
Note this version is not retina - use bootstrap's .img-retina() from mixins.less instead of the background line above when you're serving hdpi images…