I'm trying to use css varible in my Angular application, inside a child component, and it's just not working. In the browser's Elements tool (I'm using Chrome latest version) the var() doesn't do anything. expamle:
css file:
:root {
--width: 43.75%;
}
#content {
display: grid;
grid-template-columns: repeat(2, var(--width));
grid-auto-rows: 90%;
grid-gap: 3px;
align-content: center;
justify-content: center;
border: 2px solid black;
width: 400px;
height: 250px;
margin: 0 auto;
}
And thats how it's shown in the browser:
Is CSS Variables can work with Angulat at all? Thank you
Angular applications are styled with standard CSS. That means you can apply everything you know about CSS stylesheets, selectors, rules, and media queries directly to Angular applications. Additionally, Angular can bundle component styles with components, enabling a more modular design than regular stylesheets.
CSS variables have access to the DOM, which means that you can create variables with local or global scope, change the variables with JavaScript, and change the variables based on media queries. A good way to use CSS variables is when it comes to the colors of your design.
With the help of Angular CLI, you can install CSS or SCSS on your project and start working on that in a suitable way. If you are working with the CSS or SCSS in your angular project then it is very easy for you as compared to most other frameworks.
The Angular CLI can help you stylev12 introduced the option to use inline Sass in your Angular components. The CLI now has an option to provide a inlineStyleLanguage and compiles Sass directly from your Angular components into styling.
I know this is old, but a better solution than ::ng-deep is to use :host instead. This will avoid issues later on when ::ng-deep is deprecated.
:host {
--width: 43.75%;
}
Your root selector probably gets also attribute with angular component id.
Try this
::ng-deep :root {
--width: 43.75%;
}
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