Performance: Mixin definition with @mixin
This affects CSS generation size and browser rendering by reusing style blocks efficiently.
@mixin blue-box { background-color: blue; border-radius: 0.5rem; padding: 1rem; } button { @include blue-box; } .card { @include blue-box; }
button {
background-color: blue;
border-radius: 0.5rem;
padding: 1rem;
}
.card {
background-color: blue;
border-radius: 0.5rem;
padding: 1rem;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated styles without mixin | No change | No change | Higher due to larger CSS | [X] Bad |
| Styles reused with @mixin | No change | No change | Lower due to smaller CSS | [OK] Good |
@mixin in Sass?@mixin does@mixin is used to write reusable CSS blocks that can be included multiple times.@mixin.button-style in Sass?@mixin name { ... }.@mixin button-style { ... }, which is correct. @include button-style { color: blue; } uses @include which is for using mixins, not defining. Options C and D have invalid syntax.@mixin box-shadow($x, $y, $blur, $color) {
box-shadow: $x $y $blur $color;
}
.button {
@include box-shadow(2px, 4px, 6px, rgba(0,0,0,0.3));
}.button class?box-shadow takes four parameters and sets the CSS box-shadow property using them.@include box-shadow(2px, 4px, 6px, rgba(0,0,0,0.3)) replaces variables with these values, producing box-shadow: 2px 4px 6px rgba(0,0,0,0.3);.@mixin border-radius($radius) {
border-radius: $radius;
}
.box {
@mixin border-radius(10px);
}@mixin but applied with @include.@mixin border-radius(10px); inside .box, which is wrong. It should be @include border-radius(10px);.responsive-text that sets font size differently for small and large screens. Which of these mixin definitions correctly uses parameters and media queries?Pass the test and this pattern moves unknown