Questions tagged [less-mixins]

In Less, any selector with a group of CSS properties can be referred to as a mixin. Using mixins allow users to inherit/embed properties of one selector into another by just calling it within the selector which needs to inherit the properties. Use this tag for any questions related to Less mixins and their features. For other types of mixins, please use the generic mixins tag.

Any selector with a group of CSS properties can be referred to as a mixin. Using mixins allow users to inherit/embed properties of one selector into another by just calling it within the selector which needs to inherit the properties.

.default-props{ /* a simple mixin */
  font-size: 16px;
  letter-spacing: 1em;
  color: black;
  padding: 4px;
}

div, p{
  .default-props; /* mixin call will assign all default properties to div and p tags */
}

When the mixins are defined, the parentheses are optional. But when parentheses are used, the base mixin itself is not output in the compiled CSS.

Mixins can also accept input parameters and behave like functions. The parameters that are passed can be used to assign values to properties (or) in guards to help in decision making etc.

.padding-gen(@gutter-size; @direction){
  & when (@direction = all){ /* guards for decision making */
    padding: @gutter-size; /* value assignment */
  }
  & when not (@direction = all){
    padding-@{direction}: @gutter-size;
  }
}

/* mixin usage */

div#demo{
  .padding-gen(4px; all);
}
p#demo2{
  .padding-gen(2px; left);
}

Reference Links:


Collection of Common & Useful Mixins:

151 questions
0
votes
1 answer

Prevent Compilation of Unused LESS Class

I have a basic mixin class that I want to use in hundreds of classes .MainContentView { /*blah blah blah dee dah*/ } .WorkspaceView1 { .MainContentView; .LightTealGradientBackground; /* blah blah blah hoo bah*/ } But I don't want…
Calicoder
  • 1,322
  • 1
  • 19
  • 37
0
votes
1 answer

How to pass value from Angular 1 to SCSS Mixins?

is there a way to pass value from Angular (version 1.5.2) controller to mixins in the SASS? I do have mixin which display elements according to two input values which are accessible in controller and template. I have tried ng-style but that does not…
Ender
  • 158
  • 1
  • 9
0
votes
1 answer

Loop issues with Less

I am trying to create the following Less via a loop. @brand-gold: #bd9e5e; &.brand-gold { background:@brand-gold; } &.brand-gold-20 { background: tint(@brand-gold, 80%) } &.brand-gold-40 { background: tint(@brand-gold, 60%) } &.brand-gold-60 { …
davidjh
  • 387
  • 1
  • 7
  • 13
0
votes
1 answer

What is the role of mixins in bootstrap?

I am a beginner in bootstrap and I'm not able to understand this concept. What's the meaning of the less code below? // Creates wrapper for a series of columns .make-row(@gutter: @grid-gutter-width) { // Then clear the floated columns …
user6937827
0
votes
1 answer

SASS add custom parameter to media query inside @mixin

I've created @mixin in SASS to do media queries for me; @mixin break($bp1, $minmax:minmax, $media:screen, $bp2:null){ @if $minmax == "minmax" and variable-exists(bp1) and $bp2{ @media #{$media} and (min-width: $bp1) and (max-width:…
sjiamnocna
  • 167
  • 1
  • 11
0
votes
1 answer

How to make a color scheme for sub sites

I have a question on how to set up a clever way of making a theme of some sort. I'm working with Bootstrap 3.3.7 and less. The challenge is this: I have a company website with three departments. Each department has its own color. This color is used…
Meek
  • 3,086
  • 9
  • 38
  • 64
0
votes
2 answers

Create a variable list in LESS for colors variants based on a base color

In our project we use a LESS variables list. In this list we have multiple colors. For example this: @color-gray: #B9B9BA; @color-gray-light: lighten(@color-gray, 10%); @color-gray-lighter: lighten(@color-gray, 20%); @color-gray-lightest:…
0
votes
0 answers

LESS Recursive Mixin

I am trying to create a series of bars which mimic the layout of the signal strength bars on cell phones, much like this: Where the bar widths from top to bottom are 100%, 75%, 50%, and 25% Here is a plunker with the code... the styles assigned in…
Manningham
  • 335
  • 4
  • 14
0
votes
0 answers

LESS mixin for generation media queries

I'm trying to create a mixin that automates creation of media queries for predefined screen resolutions and base (template design) width. I've made some workaround and it actually works as acspected, but only for the first call of mixin. Try the…
mosgaz
  • 51
  • 4
0
votes
0 answers

Call a LESS mixin by variable name

just a short question. Is it possible to call a mixin by a variable name? Example: .for(@special-units); .-each(@value) { &.f-@{value} { //call a mixin which has the same name like @value } }
0
votes
1 answer

Unable to execute a Less CSS loop properly

I'm trying to create different loops (the class should have a different background colours), but I'm able to only compile the first one. Here's an example: http://codepen.io/anon/pen/MyWgdo?editors=1100 And the code that i'm using: @temp0-9:…
Nick
  • 13,493
  • 8
  • 51
  • 98
0
votes
0 answers

Less loop trought array with mixin guard

I'm searching for an answer about this: I got a mixins with a loop inside: @global-language-array: fr, de, es, en; @language-array-length: length(@global-language-array); .landing-specific( @landing-name, …
0
votes
1 answer

Using LESS :extend() with :lang()

Am working on a multi language website css where every UI component has different font paramaters based on different language. The use of mixin to create the output is working, but generating duplicate code. Am looking for a better solution which…
Anooj
  • 286
  • 3
  • 13
0
votes
0 answers

less css extract function

suppose .spacer(@property,@val){ @val: @val1, @val2, @val3, @val4; .mixin() when (length(@list) = 2){ @{property}:extract(@list, 1 2); }& when (length(@val) = 3){ @{property}:extract(@list, 1 2 4); } …
vssadineni
  • 454
  • 4
  • 11
0
votes
1 answer

How can I loop through a list of values in Less?

I have 5 colors and 1 mixin: @sec-blue: #29a1eb; @sec-purple: #3b519f; @sec-yellow: #ffda2e; @sec-green: #83c99e; @sec-brown: #cd9d76; .bgcollighten(@col,@per){ @result: lighten(@col, @per); } and I want to use it on #section, #subsection and…
sooon
  • 4,718
  • 8
  • 63
  • 116