sass - How to overwrite css variables value with scss variables - Stack Overflow

I am working with primeng and would like to overwrite the css variable value.(this is not important bu

I am working with primeng and would like to overwrite the css variable value. (this is not important but this will make my issue more clear and what I try to achieve)

for example if I have an badge and i would like to set the background color.

in my debug console I can retrieve the styling that is applied.

background: var(--p-badge-primary-background);

in my stylesheet I have the following code

@import "styleGuide";

.p-badge {
  --p-badge-primary-background: red;
}

this works fine but I have a whole styleguide defined and I want to use this as a template so I can changed the layout/style with minimal changes. I don't want look for al the refences of specific color. (here I overwrite a css varible with a new value)

What I like to achieve is to use a scss variables for the value that is defined in my styleguide that I imported.

.p-badge {
  --p-badge-primary-background: $color-brand-primairy; 
}
    

I am working with primeng and would like to overwrite the css variable value. (this is not important but this will make my issue more clear and what I try to achieve)

for example if I have an badge and i would like to set the background color.

in my debug console I can retrieve the styling that is applied.

background: var(--p-badge-primary-background);

in my stylesheet I have the following code

@import "styleGuide";

.p-badge {
  --p-badge-primary-background: red;
}

this works fine but I have a whole styleguide defined and I want to use this as a template so I can changed the layout/style with minimal changes. I don't want look for al the refences of specific color. (here I overwrite a css varible with a new value)

What I like to achieve is to use a scss variables for the value that is defined in my styleguide that I imported.

.p-badge {
  --p-badge-primary-background: $color-brand-primairy; 
}
    
Share Improve this question edited Mar 20 at 13:56 Naren Murali 60.3k5 gold badges44 silver badges78 bronze badges asked Mar 20 at 13:50 BabulaasBabulaas 8894 gold badges16 silver badges51 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

You can use interpolation to do this.

SASS Interpolation Docs

.p-badge {
  --p-badge-primary-background: #{$color-brand-primary};
}

What I do is this:

on helpers.scss

@use 'variables' as vars;

on _variables.scss

$black: #000;
$white: #fff;

$colors: (
  'black': $black,
  'white': $white,
);
:root {
  @each $name, $color in $colors {
    --#{$name}: #{$color};
  }
}

and I get on main.css

:root {
  --black: #000;
  --white: #fff;
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744405126a4572591.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信