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

How to include global styles in custom angular library

I have a running Angular 7 application and I am trying to create custom control library.I have some global styles that needs to be imported into the Angular application from this control library. I am trying to achieve something like the…
Asif Zaidi
  • 123
  • 3
  • 20
3
votes
1 answer

Why can I only set mat-elevation settings at the component level css?

I am using Angular material in my Angular 8 project and am trying to set up the design of the shadow on my material cards. I am using the elevation helper mixins as described here: https://material.angular.io/guide/elevation Rather than customise…
3
votes
2 answers

How to display a tooltip in Jquery with custom div elements

I am designing a nav bar using jQuery and I want to display a tooltip with custom div elements on hover of the menu items. All these are dynamic and part of an api response. Here is my code- main.js $( document ).ready(function() { …
techie_questie
  • 1,434
  • 4
  • 29
  • 53
3
votes
1 answer

Angular + SCSS: how to apply style on component on parent :hover

I am trying to show my component when it's parent is hovered. The action-list component will display a list of possible actions when an element is hovered. The goal is to have a kind of contextual actions. I am using host-context to detect the when…
Mikado68
  • 113
  • 1
  • 9
3
votes
2 answers

How can I include a mixin that contains a variable, then change that variables value inside a parent combinator?

UPDATE: working CodePen with css variable solution. UPDATE: CSS-Tricks explains that css variables cascade, and the browser repaints when they change. Preprocessor variables don't have these features. Difficult to put this in clear terms... is it…
Jace Reynolds
  • 33
  • 1
  • 7
3
votes
2 answers

How to know how many Variable Arguments I passed in my function using SCSS

Im having difficulties in understanding SCSS Variable Argument. as it shown here, it's pretty easy to understand that you can add more than one argument. But I don't understand how can I do that with Maps. For example: I have this map: $spacing: ( …
3
votes
1 answer

Ionic 4: How to import mixins globally, not having to import them in specific files?

I am upgrading to Ionic 4. How can I import mixins globally and having to import the file in every sass that uses a mixin? I've tried editing angular.json, global.scss and variables.scss but no luck. It should be adding the import to global with…
Xerri
  • 4,916
  • 6
  • 45
  • 54
3
votes
3 answers

How to overwrite Referencing Parent Selector using Mixin in SCSS

I had a common used component and its scss is like this: .component { margin-right: 12px; &.specified-use-case { margin-right: 30px; &:nth-child(odd) { margin-right: 70px } } } Now I want everything…
Keming
  • 233
  • 1
  • 3
  • 11
3
votes
1 answer

Strange character appending to SCSS @mixin

In the following scenario I need to support as many browsers as possible. I am building a SCSS @mixin that prefixes background-image with vendor prefixes, but also listens to see if a linear-gradient is declared, and if it is, then prefix that as…
DanMad
  • 1,643
  • 4
  • 23
  • 58
3
votes
1 answer

How to create Sass mixin aliases with support for content blocks?

How can I define multiple names for the same mixin, with support for content blocks? Definition @mixin desktop-breakpoint { @media only screen and (min-width: 769px) { @content; } } @mixin large-breakpoint { @include…
Remi Sture
  • 12,000
  • 5
  • 22
  • 35
3
votes
4 answers

How to create a @mixin for CSS dropshadow

I am having trouble creating a @mixin for a drop shadow. The drop shadow I want in regular CSS is as follows -webkit-box-shadow: 0px 2px 3px 2px rgba(0, 0, 0, 0.2); -moz-box-shadow: 0px 2px 3px 2px rgba(0, 0, 0, 0.2); box-shadow: 0px 2px 3px 2px…
Al-76
  • 1,738
  • 6
  • 22
  • 40
3
votes
1 answer

converting less mixins to scss

I was using the following LESS mixins to generate css for bidi usage. .ltr(@ltrRules) { body[dir="ltr"] & , body[dir="rtl"] *[dir="ltr"] & , body[dir="rtl"] *[dir="ltr"]& { @ltrRules(); } } .rtl (@rtlRules) { body[dir="rtl"] & , …
epeleg
  • 10,347
  • 17
  • 101
  • 151
2
votes
1 answer

Unable to resolve Mixin error "$color: var(--bs-body-bg) is not a color", that has never occurred before

I ran the "npm run production" command as usual. But now I keep getting this error and I can't solve it. I didn't make any changes to assets (css, scss) only in controlers some code modifications. I have searched the threads on the Stack, but none…
Sahasrar
  • 63
  • 7
2
votes
1 answer

Need to increase the max-width of modal when the route click

I want to do if the logs click I need to increase the modal max-width to 80% and other routes need to set max-width to 50%. I use the ::ng-deep because their styles come from bootstrap. therefore I need to override those. but this one is not working…
Vihan Gammanpila
  • 346
  • 4
  • 10
2
votes
1 answer

media query in SCSS with mixin

I am trying to change the size of an SVG circle for different screen sizes. I set up a breakpoints file with mixins for different screen sizes like this $breakpoints: ( "xs": 0, "sm": 480px, "md": 720px, "lg": 960px, "xl": 1200px, ); My issue is…