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

Sass loop @mixin and @include

I want to create a structure like this .nav-dropdown-items { .nav-link { padding-left: 1rem; .nav-dropdown-items { .nav-link { padding-left: 2rem; ..... } } …
Irrech
  • 1,277
  • 2
  • 13
  • 18
0
votes
1 answer

Passing value from a mixin to a class, using escaped characters

I have a map generator that add a post particle: @mixin generator { @each $key, $value in $config { $infix: '\@#{$key}' !global; @content } } I used the mixin above in multiple situations to add the particle at the end,…
user3541631
  • 3,686
  • 8
  • 48
  • 115
0
votes
0 answers

Generate a grid columns in scss, with media breakpoint particle at the end

I want to generate media queries grids having the below format: I use a first large/desktop approach, with floats. It is intentional used instead of mobile-first approach. @media (max-width: 36em) { .col-1@sm { width: 25%; } .col-2@sm { …
user3541631
  • 3,686
  • 8
  • 48
  • 115
0
votes
1 answer

Colors loops in SCSS

I want to do an array of colours in SCSS $my-colors: ("green", #008000),("blue",#0000ff), ("orange",#fca644); And with this array, I would like to colour each column. Imagining that the columns could have the minimum of 4 and the maximum of 10, so…
0
votes
2 answers

Sass mixin with class name as variable and :lang()

i am trying create mixin. Something like this @mixin localesRule($class, $cssProp, $value) { .#{$class:lang(pt)}, //...other locales { $cssProp: $value; } } But got error... Can someone help me? It is possible to…
Valeriy Donika
  • 408
  • 1
  • 5
  • 15
0
votes
1 answer

Iterate variables in SCSS?

I'm writing a function to fade items in, in sequence... .sequenced-images li:nth-child(2) { animation-delay: 1s; } .sequenced-images li:nth-child(3) { animation-delay: 2s; } .sequenced-images li:nth-child(4) { animation-delay:…
Liam
  • 9,725
  • 39
  • 111
  • 209
0
votes
1 answer

Multiple variables in SASS @each statement

I'm trying pass along a couple parameters into a SASS statement to ultimately create variations on rows, and I'm not quite getting the map key correct. My goal is to get RowName, RowBGColor and RowText Color, along with passing some of the settings…
0
votes
1 answer

I'm trying to create colour variables in SASS that will style nested elements based on class being added to a parent element

From a styling point of view I can achieve what I need but it feels like I am duplicating a lot of code. I've created a very small example of what I am trying to achieve on a much bigger scale. Each difficulty level as a colour associated with it…
0
votes
2 answers

Get in SCSS Mixin inside @each vars from next array entrie

I want to higher my quality standards of frontends and build today a little helper for the background image part: .html
.scss @mixin backgroundImage($path: '/assets/images', $fileName: null, $supports: null, $fileType: '.jpg',…
Budi
  • 678
  • 2
  • 6
  • 27
0
votes
1 answer

Sass Globally Accessible Mixins

I was wondering if there is a way to make a mixin globally accessible in sass. Below is a github link. I am using SMACSS standards for file structure. https://github.com/sfp-justin/framework If you look in…
justin.esders
  • 1,316
  • 4
  • 12
  • 28
0
votes
2 answers

Calling SCSS mixin file using Javascript

I have three files .. icons.scss --> mixin code .. main.scss --> here I call the mixin using @include icon(name) .. main.js Everything until now is working perfectly as expected. But what if I want to change the value of ,name' in the mixin from…
0
votes
0 answers

SCSS: How to select "::before" which have sibling with a specific class

I have been trying to select a ::before element inside a div which have a sibling which specific class name (trumbowyg-link-button). Here, how it look like: What I've tried .trumbowyg-button-group > button.trumbowyg-link-button { &:before { …
rony36
  • 3,277
  • 1
  • 30
  • 42
0
votes
1 answer

While converting from scss file to css file how to avoid conversion of any particular scss file into css?

While converting from scss file to css file how to avoid conversion of any particular scss file into css? I have 20 scss file which eventually convert to css which make css file very large. I am trying to convert only few file to css and want to…
user7423463
0
votes
1 answer

how to use sass mixin to append a set of classes

I need help in creating a sass mixin. I have a class called vertical3, which stacks the same same image above each other 3 times. I also get a property call overlap which can range from -2 to +1 for which I have defined classes below. these overlap…
Han Che
  • 8,239
  • 19
  • 70
  • 116
0
votes
1 answer

SASS/SCSS classlist argument in mixin

I have made a mixin, for making some grid colums in a min/max media query. Looks like this: @mixin woo-grid($min: 0px, $max: 9999px, $cols: 3, $class: '') { @media only screen and (min-width: $min) and (max-width: $max){ .woocommerce,…
Emil Østervig
  • 440
  • 4
  • 20