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
2 answers

Making grid with mixins

I found and changed a code a bit so I could use it but I am missing one thing . $map: (1025: 12,768: 6 ,320: 1); @each $point , $columns in $map { @if $point == 320 { @for $i from 1 through $columns { @media (max-width: $point + px) { …
Bojan Kolano
  • 253
  • 3
  • 19
0
votes
1 answer

Can I use psuedo elements as an argument to a scss mixin?

I have a mixin that I'm referencing an "element" as the argument. @mixin themeParent ($child) { &--blue #{$child} { color: getColour("theme", "bluehighlight"); } &--green #{$child} { color: getColour("theme",…
DumbDevGirl42069
  • 891
  • 5
  • 18
  • 47
0
votes
1 answer

use the name of the classes to give a specific color using mixin in scss

I'm starting to practice with sass and I want to set any color with the percentage of red, green and blue in the class. So, the class name color-50-10-60 means 50% red, 10% green and 60% blue, the numbers can only vary in quantities of 10 in 10, so…
user8887707
0
votes
1 answer

Variable values based on class

Why can't I change a scss variable based on a class? I want the variable to be green when in class dark-mode. Css: $test: red; @mixin darkTheme { $test: green; } .theme-dark { @include darkTheme(); .test { background-color: $test; …
Mcanic
  • 1,304
  • 16
  • 22
0
votes
1 answer

Custom Bootstrap 4 breakpoint not seen in component-level styles in Angular CLI app

I am having problems declaring the scss styles using Bootstrap's media-breakpoint-up mixin after adding a new breakpoint to $grid-breakpoints. While the d-{infix}-{display} classes come out right and the section with them works just fine, the…
user776686
  • 7,933
  • 14
  • 71
  • 124
0
votes
2 answers

opencart 3.0 dashboard error 500 after refreshing cache

Good evening people. Im having trouble fixing my opencart dashboard and searching around is proving futile. Im faurly new to hosting and the opencart framework so please bear with. I had been using opencart 3 for my webstore and was happy editing it…
doug_b
  • 17
  • 5
0
votes
1 answer

SASS variable assignment inside mixin ignored

I wanted to make a dynamic SASS theme switcher so I did this after some research: $valueName: ("ui_main"); $valueLight: (yellow); $valueDark: (grey); $currentTheme: ""; @mixin theme() { $currentTheme: "light"; .light & { @content } …
user9979178
0
votes
1 answer

Sass convert variable to string

I have something like this $theme: "default"; @import "styles/themes/#{$theme}/main"; But it does not work, maybe in import sass have problem?
Miomir Dancevic
  • 6,726
  • 15
  • 74
  • 142
0
votes
0 answers

Invalid format while compiling CSS using node-sass

I am getting an error while making my page responsive. I am using @mixin to make that possible. @mixin mediaSm{ @mixin screen and (max-width:768px) { @content; } } @mixin mediaMd{ @mixin screen and (max-width:500px) { @content; …
SIDDHARTH VARSHNEY
  • 521
  • 1
  • 6
  • 17
0
votes
1 answer

Mixin for keyframes

I'm trying to do a mixin for keyframes and it keeps breaking in newer scss compilers. @mixin frame($start-position, $end-position) { 0% { background-position: $start-position; } 100% { background-position:…
Kumudu
  • 136
  • 1
  • 5
0
votes
2 answers

Responsive width with em unit in CSS

I am trying to make a custom slider for which I have found a sample code. I have customized it a bit as per my needs but unable to set the width of the slider range element appropriately. The size and transformation calculations are defined in em…
Souvik Ghosh
  • 4,456
  • 13
  • 56
  • 78
0
votes
2 answers

Sass @each and @if/else mixin snippet?

i am very newbie about Sass and i am trying to get CSS like this; .heading-lg { font-size: 11.2rem;} .heading-md { font-size: 11.2rem;} .heading-sm { font-size: 11.2rem;} And here's my SCSS Code. But all heading-xx classes gets 11.2rem. Can…
qwer4k
  • 3
  • 3
0
votes
0 answers

Wordpress theme devepment - problem with enqueuing styles

this is my first attempt at creating a Wordpress theme so I probably did smething wrong. Anyway something strange happened, some of the styles disappeared (bootstrap) but instead there are some scss files - the url points at the main theme folder,…
dobb
  • 43
  • 1
  • 1
  • 4
0
votes
0 answers

SCSS Margin-top Not working unless inside nested class

I am working on a prototype that is styled using SCSS. For some reason, when I put the margin-top: 0; on the parent element, it is not taking effect. When I put the margin-top inside the nested classes, it works. Can someone explain what I am doing…
EliTownsend
  • 181
  • 11
0
votes
0 answers

Sass: Setting global variables based on theme

I am trying to set global variables when a theme mixin is included since it seems much more straight-forward to use than this "themify" stuff I find from searching. The idea is something like having a _themes.scss with @mixin light-theme {…
Jacob Phillips
  • 8,841
  • 3
  • 51
  • 66