I've an element I want to style only if it's got two classes applied to it:
custom-select-value--companies
and
custom-select-value--companies-disabled
It's actually the pseudo element I want to style, and the following css works:
.custom-select-value--companies.custom-select-value--companies-disabled::after { // Styles }
It's probably very simple, but I was just struggling to translate that to sass and was hoping someone could help? The following doesn't work:
.custom-select-value {
&--companies.&--companies-disabled::after {
// Styles
}
}
Also, just wondered as I was writing this - what's the main element of a pseudo element called? "Parent" doesn't seem quite right?
Thanks
Managed to get it working by typing the second selector out in full:
.custom-select-value {
&--companies.custom-select-value--companies-disabled::after {
// Styles
}
}
Does anyone know how can I change mat-spinner color in Angular Material?
Overriding css doesn't work. I tried changing color in material files but they can only be imported, I can't change anything there.
I want it to be my custom color, not color from prebiult-themes.
Use this code for ** < mat-spinner >** add this code in your .css file
.mat-progress-spinner circle, .mat-spinner circle {
stroke: #3fb53f;
}
This answer will work for those who're looking for a flexible solution in Angular 4 / 6 / 7. If you wan't to change the color of a mat-spinner at a component level, you'll need to use the ::ng-deep selector. Knowing this, the solution is quite easy.
In your html file:
<div class="uploader-status">
<mat-spinner></mat-spinner>
</div>
In your css / scss file:
.uploader-status ::ng-deep .mat-progress-spinner circle, .mat-spinner circle {
stroke: #000000;
}
Notice that the .uploader-status css class encapsulates the component. You could just use ::ng-deep without using a class but then whatever changes you're doing to the mat-spinner will appear in other areas of the application. Check this to learn more.
Easy Fix!
Add custom css rules inside styles.css instead of component.css file
.mat-progress-spinner circle, .mat-spinner circle {
stroke: #2A79FF!important;
}
To your .css/.scss component file style add (it will works locally - in component only)
:host ::ng-deep .mat-progress-spinner circle, .mat-spinner circle {
stroke: #bada55;
}
If you don't want to mess around with the global css and need a way to set the spinner to different colors in different areas of your app, I would strongly recommend to create a directive for it.
import { Directive, Input, ElementRef, AfterViewInit } from '#angular/core';
#Directive({
selector: "[customSpinner]"
})
export class CustomSpinnerDirective implements AfterViewInit{
#Input() color: string;
constructor(
private elem: ElementRef
){}
ngAfterViewInit(){
if(!!this.color){
const element = this.elem.nativeElement;
const circle = element.querySelector("circle");
circle.style.stroke = this.color;
}
}
}
Then the spinner should work like this:
<mat-spinner diameter="22" customSpinner color="#fff"></mat-spinner>
mat-spinner html code :
<mat-spinner color="accent" diameter="20" class="loading"></mat-spinner>
And now sass code :
.mat-spinner {
::ng-deep circle {
stroke: #33dd82;
}
}
Color is build in.
Theming
The color of a progress-spinner can be changed by using the color property. By default, progress-spinners use the theme's primary color. This can be changed to 'accent' or 'warn'.
https://material.angular.io/components/progress-spinner/overview
example
<mat-spinner color="warn"></mat-spinner>
I think the key here is that is must be in the GLOBAL styles.css file. The below solution does work if placed there (should be the CSS file affected when material was added to the project if added with ng add:
.mat-progress-spinner circle, .mat-spinner circle {
stroke: #b68200;
}
Of course you could also add classes to the component and specify different selectors if you want distinctly styled spinners. However, it seems the classes must be in the global CSS file.
Late to the game, but this worked well in my .scss file today...
.parent-element-class {
::ng-deep
.mat-progress-spinner,
.mat-spinner {
circle {
stroke: white;
}
}
}
In your styles.css file, add...
::ng-deep .mat-progress-spinner circle, .mat-spinner circle {
stroke: #2A79FF!important;
}
As you might have guessed, I have just made a simple modification to Nitin Wahale's answer. I have prefixed his answer with ::ng-deep and it worked in my case as I had the same issue.
I hope this helps somebody
By default angular material would give your spinner default color of primary.
You can use 3 colors available in pallet that would be primary, accent, warn.
However, if your needs are of different color please consider anyone of the below options.
Easy way(not recommended)
You can use any of method to override css forcefully mention in other answers. I would recommend using parent class above spinner element if you do not want spinner to be of same color throughout the application.
The correct and recommended approach would we to use custom-theme for material. If you already have custom you can just
do like creating a custom mixin called
//here $primary-color is the color you want your spinner to be
#mixin spinner-custom-theme($primary-color, $accent-color, $warn-color) {
$custom-spinner-theme-primary: mat-palette($primary-color);
$custom-spinner-theme-accent: mat-palette($accent-color, A200, A100, A400);
$custom-spinner-theme-warn: mat-palette($warn-color);
$custom-spinner-theme: mat-light-theme($custom-theme-primary, $custom-theme-accent, $custom-theme-warn);
#include mat-progress-spinner-theme($custom-spinner-theme);
}
Now go to file where #include angular-material-theme($custom-theme);
is written
and #include your mixin just below the #include angular-material-theme($custom-theme);
To know more on how to create custom theme you can check this blog here
Sample Color, strokeWidth, diameter and title
<mat-spinner strokeWidth="24" [diameter]="85" color="warn" title="Tooltip text here"></mat-spinner>
In your css file mention like below:
::ng-deep.mat-progress-spinner circle,.mat-spinner circle {stroke: #f2aa4cff !important;}
Here, ::ng-deep will be used to force a style.
!important here what says is that "this is Important",you ignore all other rules and apply this rule.
.mat-mdc-progress-spinner { --mdc-circular-progress-active-indicator-color: white; }
This worked for me using Angular 15.
This is best achieved by doing a custom theme.
https://material.angular.io/guide/theming
use this code
<md-progress-circular md-diameter="20px"></md-progress-circular>
md-progress-circular path {
stroke: purple;
}
In case you guys want to customize each spinner on your webpage. You can do it this way:
svg .mat-progress-spinner circle, .mat-spinner circle {
stroke: inherit;
}
And now on mat-spinner add class:
<mat-spinner class="custom-spinner-color"></mat-spinner>
And in css file:
.custom-spinner-color {
stroke: #234188;
}
That was what I wanted to achieve. I suppose if you look for this question you probably want the same.
Mat progress spinner custom timer, I changed to 3 different colors based on the value passed to mat spinner. Pls refer : https://material.angular.io/components/progress-spinner/examples
<mat-progress-spinner class="mat-spinner" [color]="progressColor"
[diameter]="170" [strokeWidth]="14"[mode]="'determinate'"
[value]="progressLabel">
</mat-progress-spinner>
Ts file
timer: number = TIMER; // say 60 seconds
progressColor: ThemePalette = 'accent';
timerPercent: number = 0;
progressLabel: number = 100;
startTimer() {
this.timer = TIMER;
this.timerInterval = setInterval(() => {
if (this.timer <= 0) {
clearInterval(this.timerInterval);
this.timerFinish();
}
if (this.timer > 0) {
this.progressColor =
this.timerPercent > 69
? 'warn'
: this.timerPercent > 49
? 'primary'
: 'accent';
this.timer--;
this.timerPercent = (100 * (TIMER - this.timer)) / TIMER;
this.progressLabel = 100 - this.timerPercent;
}
}, 1000);
}
For me this is how I do it clean without messing with anything globally:
in my .css
::ng-deep .customColorSpinner circle {stroke: #4e1e1e!important;}
in my .html
<mat-spinner class="customColorSpinner"></mat-spinner>
You can use a custom Angular Directive to solve this problem. The directive allows you to set a custom color on the mat-spinner like this:
<mat-progress-spinner spinnerColor="#09ff00"></mat-progress-spinner>
I have an article here where I explain this and thoroughly show you how to solve it
In component.scss where your mat-spinner exists, just add this :
::ng-deep .mat-mdc-progress-spinner {
--mdc-circular-progress-active-indicator-color: #7D469A;
}
Hello and greetings to you all.
I have a strange reaction with css in one website that i'm making.
There is this code
<a class="instagram-photo image" id="p1130472628000663001_176824616" href="PROFILE" target="_blank" data-name="NAME" data-caption-std="Colors #thefeditor" data-caption="Colors #thefeditor <a target="_blank" href="INSTA LINK;>View Photo</a> " data-created="1448982860" data-author="AUTHORNAME" data-likes="87" data-comments="0" data-profile="PROFILE LINK" rel="group"><img src="IMAGE LINK"><span class="journal-meta">Example Name<span>username</span></span><span class="icon">Image</span></a>
The above image is set with the following background color.
media="all"
.classic-view .instagram-photo.image {
background-color: #3dc0f1;
}
I'm trying to change the blue color (#3dc0f1) color to this
background-color:rgba(255,215,0,0.6) !important;
With no luck because i want to change the color ONLY to this id
id="p1130472628000663001_176824616"
because if i go to the custom css and put this css code
.instagram-photo
{
background-color:rgba(255,215,0,0.6) !important;
}
It changes all the images, but i want to change the images with the ID that i gave you above.
I have tried
#p1130472628000663001_176824616.instagram-photo {
background-color:rgba(255,215,0,0.6) !important;
}
But it didnt work. Any idea of how can i make it work? Thanks!
P.S. the answer below is also correct but i also managed to do it with
a[id*="_176824616"][class*="image"]
{
background-color:rgba(255,215,0,0.6) !important;
}
Thanks a lot!
Why not just doing:
.instagram-photo#p1130472628000663001_176824616
{
background-color:rgba(255,215,0,0.6) !important;
}
That way, you are declaring a rule to CSS that says that you want to set the background color to an element of class instagram-photo and with id having your id - notice that the class and id are concatenated to one phrase on the rule. This is done in order to specify the rule containing both class and id on a specific element and not the nested ones.
Also, consider that for simplicity, you could simply do:
#p1130472628000663001_176824616
{
background-color:rgba(255,215,0,0.6) !important;
}
By "saying" to CSS you want to apply the rule only to the element(s) with the specific ID, without taking into consideration its class - this is specific on your case, so it should work fine.
In addition, consider avoiding using !important, as this can lead to unexpected behavior on your rules and violates the sequence the rules are applied.
I am building charts with Raphael.js that have all sorts of styling attached to them, including different hover styling. The following works across browsers:
var bar = paper.rect(x, y, width, height)
.attr({"stroke-width": 0, fill: #baeadd; "fill-opacity": 0.3})
In an attempt to fully separate the appearance from the functionality, I am trying to target my Raphael elements with CSS and add all the styling from there.
I used the technique outlined here to be able to target my shapes in all browsers, using unique ID-s:
bar.node.id = "bar-" + id;
-
*[id^="bar"] {
// Attributes listed here seem to work in modern browsers
// http://raphaeljs.com/reference.html#Element.attr
fill: #baeadd;
fill-opacity: 0.3;
}
*[id^="bar"]:hover {
fill-opacity: 0.5;
}
The above does not work on IE8, where Raphael injects vml shape elements instead. I am able to specify standard CSS properties such as background-color, and the shape element will get the styling fine, but I would like to know how to apply attributes such as fill-opacity, stroke-width, and the likes.
Is it possible to set fill and stroke colors and opacity on VML paths using CSS? explains the role of behavior: url(#default#VML). I can see that Raphael already adds a .rvml class to all the shape elements it creates, and applies this behavior property, but it doesn't seem to take effect as soon as I stop applying attributes via JS and start specifying them in the CSS.
There isn't a way of doing this since IE8 requires setting the attributes on the VML elements.
Based on my answer to Is it possible to set fill and stroke colors and opacity on VML paths using CSS?, you should be able to use a DHTML behaviour file to read the SVG styles applied in your style sheet and map them to the corresponding VML attributes.
Start by creating the behavior file, eg: vmlcss.htc
<PUBLIC:COMPONENT>
<SCRIPT LANGUAGE="JScript">
var currentStyle = element.currentStyle;
if (currentStyle)
{
// Apply stroke style
element.stroked = currentStyle["stroke"] && currentStyle["stroke"] != "none";
if (element.stroked)
{
element.strokecolor = currentStyle["stroke"] || "none";
element.strokeweight = currentStyle["stroke-width"] || "1px";
}
// Apply fill style
element.filled = currentStyle["fill"] != "none";
if (element.filled)
{
element.fillcolor = currentStyle["fill"] || "Black";
}
}
</SCRIPT>
</PUBLIC:COMPONENT>
Then add this block to your pages in order to apply this new behavior to the VML elements:
<style>
.rvml
{
behavior: url(#default#VML) url(vmlcss.htc);
}
</style>
That's all. The stroke color and fill color specified in your CSS should now be applied to the VML elements when running IE<9.
You may further extend the behavior file to map other SVG styles to VML attributes as needed.
In my opinion, Raphael should offer the possibility to specify either identifiers or class names for the created shapes, making styling via CSS much easier.
Note: I was not able to test this code, please let me know if there are issues with it so that we can improve the answer.
I was wondering how I could set up css pseudo classes, specifically hover so when I hover over an element, like a div with an id, the properties of a different div with an id get changed?
so normally it would be this:
#3dstack:hover {
listed properties
}
I'm not sure what the change would be to have it hover on div with the id 3dstack and have it change another div.
I do not think that is possible unless the element you want to change the properties of is a descendent or a sibling of the hovered element, in which case you can do:
#myElement:hover #myElementDescendent {
background-color: blue;
}
/*or*/
#myElement:hover + #myElementSibling {
background-color: blue;
}
Of course you can always use jquery to do this:
$("#anelement").hover(
function() {
$("otherelement").css("background-color", "blue");
});
See the differences here
This is not possible with CSS alone. You'll have to use a JavaScript event handler. For example, with jQuery's hover:
$('#3dstack').hover(function() {
$('#otherID').toggleClass('properties');
});
DEMO
Visually you can do this using LESS, but under the hood it's actually using JavaScript.