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

Working on a sas mixins to attach the values based on the margin-position

Hi Iam writing a mixins where I want to attach the values based on the margin position I have come far this not sure how to move forward. @mixin margin ($value, $positions...){ @each $position in $positions { margin-#{$position}: $value; …
Benjamin
  • 2,612
  • 2
  • 20
  • 32
0
votes
3 answers

SASS function to iterate nth-child(n+1) and lighten/darken($color, 5n%)

I use a lot of SASS/SCSS, but don't usually use complex any functions. My current need seems like the perfect use-case for a function but not sure how to loop like this in SASS/SCSS. I need a stepped colour pattern that changes the background…
Rhecil Codes
  • 511
  • 4
  • 24
0
votes
1 answer

Sass use variable value in @import

My code looks like this &.village { &.village- { @for $i from 1 through 12 { &#{$i} { background-image: url('../../images/maps/#{$i}.png'); @import "maps/map-#{$i}"; } …
user936965
0
votes
2 answers

how to select parent item with scss

I have the following HTML:
user936965
0
votes
2 answers

Get only the imediate parent, not all path, using placeholders

I have the following sass: %slider { .c-slider { $parent: &; &--thumb { #{$parent}__item{ margin:0; } } } } .l-cap { @extend %slider; } and I get: .l-cap .c-slider--thumb .l-cap .c-slider__item {margin: 0; } But…
user3541631
  • 3,686
  • 8
  • 48
  • 115
0
votes
2 answers

Bootstrap, scss, use some class name in scss code instead of writing it in html files

In Bootstrap 4 I can use text-truncate as a class in an element. Eg: Any very long text What I need now is to use this class text-truncate in a scss file for many objects instead of writing it directly in .html…
user4412054
0
votes
1 answer

SCSS - Combining/shorten/simplify code with parametres?

Is it somehow possible to combine this SCSS code with parametres or something similar? I just don't know how to do that. This code is about styling the different types of input fields in SCSS. I had do to it this way because I didn't want to delete…
Miggi
  • 13
  • 2
0
votes
1 answer

Vaadin setting background not working

So i'm a bit confused as to why setting a background image is not working. I can use other SCSS methods like .top etc to set colours etc but when it comes to pulling images through SCSS the application comes up with an error. mytheme: @import…
James Palfrey
  • 753
  • 6
  • 29
0
votes
1 answer

SCSS Mixing not working

I am trying to learn mixin's with SCSS, I am trying to make a simple mixin to control the style of buttons, however it is not working. I am sure I have missed something obvious, but I am pulling my hair out now. Any advice would be much…
Harry Blue
  • 4,202
  • 10
  • 39
  • 78
0
votes
2 answers

Can't customize color of default search component

I have an Ionic 3 app I'm working on where I have a search field. I'm trying to color it with a dark background and white text. I have the following code, which works fine on the background, but the default icon and placeholder text are not turning…
cnak2
  • 1,711
  • 3
  • 28
  • 53
0
votes
1 answer

How to change the variable value used within another variable from the scss mixin

I tried to change the variable used in another variable from the mixin, but I couldn't change the variable value. $color: white !default; $var: "this #{$color} is a test" ; @mixin test($value, $color) { // here how to override the $color value …
Yahwe Raj
  • 1,947
  • 5
  • 25
  • 37
0
votes
1 answer

I don't understand that mixin - I need some explanation

I'm new to mixins and I try to understand this one. Could you please explain this particular one to me? What does it do? @mixin _position($position, $args) { @each $dir in top, left, bottom, right { $i: index($args, $dir); @if $i { …
John Taylor
  • 729
  • 3
  • 11
  • 22
0
votes
1 answer

SASS generates two separate rules for same class using extend and mixins

In this SCSS code, I'm using mixin btn-structure and extend %red-color to get all declarations under one class contrary to my expectation SCSS output two separate rules for the same class as shown in output below: %red-color{ color: red } @mixin…
dkjain
  • 831
  • 1
  • 9
  • 36
0
votes
1 answer

SCSS Syntax Error When Using Include-media

I am using include-media in a project and getting the syntax error [scss] ) expected when viewing this mixin in my vscode editor. I have had a look at this question, but it is not about the same syntax I am experiencing. Here is a screenshot of…
Siya Mzam
  • 4,655
  • 1
  • 26
  • 44
-1
votes
1 answer

Variable in scss

VS code does not recognize variables ($). at-rule or selector expected { expected I tried restart, shut down, uninstall VS Code, copy to new file ... $color1: aqua; $color2: #333; $color3: rgba(136, 0, 0, 0.75); $color4: rgba(255, 153, 51, 0.75);