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
0
votes
1 answer

Use SASS @each variable inside nested mixin

I want to use Sass's built-in @each method to shorten this code: .svg-circle-full { @include mixinSVG(( 'svg': $svgvar-icn-circle-full, 'isWide': false )...); } .svg-circle-empty { @include mixinSVG(( 'svg':…
JordanBarber
  • 2,041
  • 5
  • 34
  • 62
0
votes
1 answer

Can a SCSS @each loop contain multiple maps?

I'm trying to build a SCSS @each loop which calls a color from one map, and an opacity from another map. I've found this can be done with variable lists, however can it be done with maps? Example code: $colors: ( red: red, orange: orange, …
410er0r
  • 3
  • 2
0
votes
1 answer

How to import style files into an Angular +2 project in an optimized way?

Im working with Angular Material theme into an Angular 6 project, I have 3 style files: 1) styles.scss (main style file, it's define into Angular.json file) @import "styles/themes/blue-light.scss"; // Basics * { margin: 0; padding:…
juanjinario
  • 596
  • 1
  • 9
  • 24
0
votes
1 answer

How to use a mixin to create a string from an undefined length array in scss?

The answer from here works for me for preloading images: https://stackoverflow.com/a/14390213/533426 body::after{ position:absolute; width:0; height:0; overflow:hidden; z-index:-1; content:url(img01.png) url(img02.png) url(img03.png)…
Toskan
  • 13,911
  • 14
  • 95
  • 185
0
votes
2 answers

Why is my sass mixin not compiling into css?

I'm new to sass and currently exploring it. I want to try using mixin but when I tried it, it's just not working. Here's the code: @mixin container($radius, $width, $height, $bg, $color) { -webkit-border-radius: $radius; -moz-border-radius:…
catto1297
  • 5
  • 5
0
votes
0 answers

Sass mixin @content not letting grids working properly

I'm having an odd issue, I'm new to using the @mixin and @content tag, and sass in general for that matter, but for some reason, my grid-template-areas don't accurately represent what I want them to. HTML
James Andrew
  • 197
  • 1
  • 4
  • 16
0
votes
1 answer

How to assign the mixin $variable in scss file to an html element's class

In my component.scss file, I have got mixin variable, I'm trying to set the ripple color for a div element. if I set a direct color value eg: [matRippleColor]="red" in the HTML, The ripple color is applied and working. however, if I give the mixin…
Pradeep
  • 581
  • 3
  • 11
  • 19
0
votes
2 answers

Dynamic font sizing with SCSS

Is it possible to set the font size relative to another element's font size using only SCSS and not JS? For example, I want to get paragraph text 2 pixels smaller then input. I've attempted something like this but it does not seem to…
santa
  • 12,234
  • 49
  • 155
  • 255
0
votes
2 answers

Trying to create a row with 4 cells

I am trying to create a row with 4 cells and I don't know why its not working. I have created a parent row and 4 children.
hi
Sarmad Shah
  • 3,725
  • 1
  • 20
  • 42
0
votes
2 answers

Cannot return all the key names of my SCSS map using function

I have a color map and I need to return only the keys of this map using the function. But I can return only the first key name. I tried to take all name of the keys call section-color, tree-line-color, table-header-color, table-cell-color. But I…
0
votes
1 answer

SCSS mixin dynamic class name evaluates without quotation mark

I'm using the following SCSS mixin @mixin QuintIcon($path, $name, $color) { ion-icon { &[class*=#{quote($name)}] { mask-image: url($path); color: #{$color}; } } } @include QuintIcon("../../assets/img/tabs/rings.svg",…
0
votes
1 answer

Converting LESS "when" statements into SCSS conditional statements

To cite my sources, I'm converting the tiles functionality from Metro-UI into a custom SCSS/Angular project I'm building. So far I've been able to convert much of it 1:1 by watching for mixins, includes, and variables. However, I'm not following…
0
votes
1 answer

scss interpolation help for passing the values

I need to create dynamic classes for which I am creating a scss code to create the classes for all the possible values. Below is my code:- $colors: ( "black": "0,0,0", "white": "255,255,255", "red" : "255,0,0" ); $opacity:9; @for $i…
Yogesh
  • 331
  • 1
  • 4
  • 10
0
votes
0 answers

Proper way to format a custom mixin button in scss

EDIT: I was just overthinking it. Now I've added more variables to the mixin like this to make all the colour correct: @mixin CustomBtn($border-color, $transparent: transparent, $text-color, $bg-hover-color, $text-hover-color) I've got a…
Krullmizter
  • 529
  • 8
  • 28
0
votes
0 answers

What does # mean in SCSS

what does # mean in SCSS. I just want to understand what it means. @mixin hoverFocus($property, $value) { &:hover, &:focus { #{$property}: $value; } }
Chezka Summer
  • 15
  • 1
  • 5