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

Sass: applying a shared class to every selector in a content block

If I have a block of styles in Sass like this: .class1 { .class2 { } .class3 { .class4 { } } } How can I use Sass to transform the above into the form below? I would like to avoid repeatedly typing .class or…
schen7913
  • 21
  • 1
2
votes
2 answers

What is the best way to use the container class for a component?

I am trying to build a card. I am supposed to use some styling from a different project. The structure of the card is as follows:
This is the body
The mixin for the…
pree
  • 239
  • 1
  • 3
  • 12
2
votes
1 answer

Overriding isolated css in blazor component library by consuming application

I have set up a blazor component library that defines several blazor components + isolated CSS files. These css files are transpiled from sass files in which I specify the bootstrap grid system using bootstrap's mixins, e.g. @include…
Tom
  • 332
  • 2
  • 13
2
votes
1 answer

Problem with Scss+Pug+Webpack configuration

I have a problem with scss webpack processing. scss file is copied to result html as is, looks like preprocessor was not executed. In result html file I see '&' symbols in style section: .container { margin-top: 120px; display: flex; …
2
votes
0 answers

Vue Enterprise Boilerplate: sass-loader unable to load from updated .scss files

I'm rewriting an existing project using the latest vue enterprise boilerplate. I haven't been able to find any examples of the use of vue enterprise boilerplate so I'm doing trial and error. When using some of the existing code with large