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

How to target all scss variables which is used for styling with regex

Hi i want to target all the scss variables which is used for styles Question: i want to target all the scss variables which comes after : with $name it might come inside ($name) as shown in below image (red color highlight) My Expectation is shown…
EaBengaluru
  • 131
  • 2
  • 17
  • 59
2
votes
0 answers

Angular 14 Angular Material Themes - 'Can't find stylesheet to import' in Visual Studio, but builds with 'ng build'

I have an Angular 14 app which is built as part of an existing ASP.NET MVC Core app in Visual Studio. The angular project is a folder in the existing MVC application, so my project looks a little like this: . ├── Program.cs ├── Startup.cs ├──…
Irish Yobbo
  • 403
  • 1
  • 6
  • 21
2
votes
1 answer

Sass undefined mixin error - How to make main style file loads first

I've installed an app using CRA and want to use SASS with it (I'm a new one in SASS installation and familiar with syntax) Currently, I have this folders structure: |── package.json | ├── README.md ├── src │ | │ ├── index.css │ ├── index.js │ …
2
votes
0 answers

How can i spicify slector rule conditionally in sass?

I'm new to scss, I want to implement theming using scss, I wrote mixins and function that returns a color value if parent class. i.e "theme-light" or "theme-dark" exits accordingly. How can I write a selector that returns a default value if the…
2
votes
1 answer

Why isn't my scss code appearing when I run my code. I linked it to my html file?

Why isn't my scss code appearing when I run my code? I linked it to my html file in this format . /* dynamic pyramid image, code of my scss file below */ /* dynamic pyramid image */ $color:…
2
votes
2 answers

Implementation of dark mode with variables in React/Sass project

I am working on a Sass project and I am pretty new to it. I have a _variables.scss file which contains the variables for UI. I want to change the values of those variables dynamically (not creating new ones), with the use of React. How can I do…
crosie
  • 45
  • 1
  • 4
2
votes
1 answer

Problems accessing the color value defined in the tailwind.config.js file (in scss file)

in a project with Tailwind i need to darken a color defined in the tailwind.config.js (directly in the scss file). @debug "Darken Color: #{darken(theme("colors.gray.500"), 10%)}"; This cause the error: SassError: $color: theme("colors.gray.500") is…
Gabriele Muscas
  • 1,325
  • 1
  • 9
  • 16
2
votes
2 answers

Variables inside @media query in .SCSS files not working

In my angular application, I am writing scss for responsive design & I have few SASS variables declared outside & inside the media queries, but the variables declared inside the media query are not working. In fonts.scss which is placed in 'styles'…
user1199842
  • 151
  • 2
  • 14
2
votes
4 answers

Tailwindcss version 3 classes not working on class attributes, but works on @apply for Angular 13

I'm unable to get Tailwindcss classes to appear on the inline "class" attribute. But if I @apply I through the ".scss" file and use that class on the inline "class" attribute it works fine. Does not work: .HTML
syahiruddin
  • 401
  • 5
  • 14
2
votes
1 answer

How to use scss @include

I have a SCSS file, and I want to @include transition(all, 0.5s); But scss gives Error message: Scss compiler Error: no mixin named transition Here is my SCSS: a { float: left; line-height: 70px; text-decoration: none; color: white; …
Nbody
  • 1,168
  • 7
  • 33
2
votes
1 answer

SASS @mixin compiling in .css file

Trying to understand why SASS is compiling wrong in CSS: in _typography.scss I have: @mixin fontType ($type) { @if $type=="normal" { @font-face { font-family: "gotham"; font-weight: normal; font-style:…
aberry
  • 21
  • 1
2
votes
1 answer

Getting Error passing Media Queries to a SASS mixin: Error: Undefined mixin

I'm getting an error while passing the mixins into my scss file, i used the same mixins to my another project and it worked fine. but when i try to use the same mixins i get an error. here is the code:- .carousel-wrapper { padding: 0 0…
2
votes
1 answer

SCSS font-stack mixin error: "argument `$map` of `map-get($map, $key)` must be a map"

I have a problem with this mixin in my project where I'm using gulp-sass: $base-font-stack: ( sfprodisplay: ( regular: ( family: (SFProDisplay, sans-serif), weight: 400, style: normal ), bold: ( …
user15478819
2
votes
1 answer

SassError: expected ")"

Working environment: Angular with SASS/SCSS I'm working on the Angular project and I keep getting this error. I was trying to add a custom theme palette to the SASS file. Any idea? Failed to compile. ./src/styles.sass…
Ian Lee
  • 43
  • 1
  • 7
2
votes
1 answer

Angular material Sass get styles dynamically via map-get and dark theme on global scss files

I have implemented dark theme in my Angular application. It's done via Service and adds or remove a class to the document body. this.renderer.addClass(document.body, 'color-scheme-dark'); Styles.scss is including the material theme according to the…
Or05230
  • 83
  • 9