Questions tagged [scss-mixins]

Mixins allow you to define styles that can be re-used throughout your stylesheet

One of the most important usages of mixins is to avoid using non-semantic classes like .float-left.

Mixins are defined using the @mixin at-rule, which is written

@mixin <name> { ... } or @mixin name(<arguments...>) { ... }

A mixin’s name can be any Sass identifier, and it can contain any statement other than top-level statements.

Example of mixin in SCSS:

@mixin reset-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

@mixin horizontal-list {
  @include reset-list;

  li {
    display: inline-block;
    margin: {
      left: -2px;
      right: 2em;
    }
  }
}

nav ul {
  @include horizontal-list;
}

Result in CSS:

nav ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
nav ul li {
  display: inline-block;
  margin-left: -2px;
  margin-right: 2em;
}
655 questions
4
votes
1 answer

Angular-mdc returning "No mixin named mdc-top-app-bar-fill-color"

So, I'm using angularCLI and angular-MDC, I want to use the second color of my styles.scss. There is on site https://trimox.github.io/angular-mdc-web/#/angular-mdc-web/top-app-bar-demo/sass this syntax mdc-top-app-bar-fill-color($color) I used and…
4
votes
2 answers

Scss Variable based on class

I am trying to do theming for one of my projects and i was using css variables for the same. I was defining css variable as follows .theme-1 { --var-1: #ffe; --var-2: #000; } .theme-2 { --var-1: #fff; --var-2: #000; } and in the…
Vikhyath Maiya
  • 3,122
  • 3
  • 34
  • 68
4
votes
1 answer

Media selectors "extending" bootstrap SASS classes

On a site I'm developing w/ Bootstrap/SASS (SCSS) I'd like to have a Bootstrap button group (.btn-group) become a vertical group (.btn-group-vertical) using media selectors, rather than JavaScript. However, the well-known issues that @extend will…
3
votes
2 answers

Ampersand (&) as a variable inside SASS @mixin

Looking up Bootstrap 5 code, I faced this following statement on bootstrap/scss/mixins/_forms.scss file: @mixin form-validation-state-selector($state) { @if ($state == "valid" or $state == "invalid") { .was-validated #{if(&, "&",…
artu-hnrq
  • 1,343
  • 1
  • 8
  • 30
3
votes
2 answers

Use Bootstrap's utility API from my scss file

The Bootstrap docs explain how to enable negative margins - but that is for the case where one customises Bootstrap. I'm using it from a CDN, but I still want those classes (e.g. mt-n1). I'd like to import them via a mixin (or something like that)…
lonix
  • 14,255
  • 23
  • 85
  • 176
3
votes
1 answer

Generate CSS classes dynamically based on variables - SCSS

I have color variables (example): // _colors.scss :root, * { --color-primary-50: 1,1,1; --color-primary-100: 2,2,2; --color-primary-200: 3,3,3; } And I want to generate classes based on the variables, for example: //…
Anton S.
  • 969
  • 1
  • 11
  • 29
3
votes
1 answer

Convert opacity with var scss sass

I have some property like this ::root { --light-grey: #EFEFEF; } .content-wrapper { background-color: rgba(#EFEFEF, .4); border-radius: 8px; padding: 25px 33px; } But when I try .content-wrapper { background-color:…
Miomir Dancevic
  • 6,726
  • 15
  • 74
  • 142
3
votes
0 answers

Angular Material 12 custom theming for components is not working as expected

I am completely lost here and all of the documentation you can find here or medium doesn't seem to be helping and it seems outdated. Specifically, I am trying to use @mixins or adjust parts of the components theme aspects. In I can get the…
Christian Matthew
  • 4,014
  • 4
  • 33
  • 43
3
votes
1 answer

Ag-param() called before ag-register-params

I try to generate a custom theme for Ag-Grid with the new theme mixin. But I always get the following error: ERROR in ./src/app/style.scss…
JuNe
  • 1,911
  • 9
  • 28
3
votes
2 answers

Generate linear gradient in a for loop in SCSS

I Have written a mixin to create for a background with 4 side-by-side lines at any size and any angle at any position by taking advantage of linear-gradient however I am wondering if there would be a way to make it more dynamic? @mixin…
pfych
  • 850
  • 1
  • 13
  • 32
3
votes
2 answers

Angular 9 / Material - Reuse of material theme variables in angular components style

I have standard angular 9 application with material theming. We experienced the problem of increased bundles sizes and found out that our reuse of scss styles causes this increase. The issue was that imported scss was compiled in the component as…
wami
  • 435
  • 3
  • 10
3
votes
2 answers

Angular - how to theme my own component using mixin?

I created a component: message.component.html
Cedric Arnould
  • 1,991
  • 4
  • 29
  • 49
3
votes
2 answers

How to pass multiple content blocks as arguments to a mixin?

I wanna be able to do something like so: .myTransitionableElement { transition: all .5s; .subChild { transition: all 1s } @include transitionKeyframes( start: { opacity: 0; transform: tranlsate(50px); .subChild { …
Daniel Birowsky Popeski
  • 8,752
  • 12
  • 60
  • 125
3
votes
1 answer

How to simulate Material UI's "theme.mixins.toolbar" using SASS

Pretty simple question here. I have been in an Mui/React/Scss rabbit hole trying to find straightforward answers around styling Mui components using SASS, and without using JSS, themes, withStyles, etc. This is a client requirement. I am currently…
BWeb303
  • 303
  • 6
  • 18
3
votes
0 answers

Does removing redundant SCSS imports affect compile time?

Lets say I have a file variables.scss and mixins.scss In my file component.scss I import both. But mixins.scss itself, imports variables.scss. Is this redundant? Does it matter? Does removing the variables.scss import in component file make any…
Akin Hwan
  • 607
  • 1
  • 9
  • 26
1 2
3
43 44