mirror of
https://github.com/danog/sass-site.git
synced 2025-01-09 14:38:39 +01:00
48 lines
929 B
Plaintext
48 lines
929 B
Plaintext
|
{% markdown %}
|
||
|
For example, suppose you want to write a selector that matches the outer
|
||
|
selector *and* an element selector. You could write a mixin like this one that uses the [`selector.unify()` function][] to combine `&` with a user's selector.
|
||
|
|
||
|
[`selector.unify()` function]: ../../modules/selector#unify
|
||
|
{% endmarkdown %}
|
||
|
|
||
|
{% codeExample 'advanced-nesting' %}
|
||
|
@use "sass:selector";
|
||
|
|
||
|
@mixin unify-parent($child) {
|
||
|
@at-root #{selector.unify(&, $child)} {
|
||
|
@content;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
.wrapper .field {
|
||
|
@include unify-parent("input") {
|
||
|
/* ... */
|
||
|
}
|
||
|
@include unify-parent("select") {
|
||
|
/* ... */
|
||
|
}
|
||
|
}
|
||
|
===
|
||
|
@use "sass:selector"
|
||
|
|
||
|
@mixin unify-parent($child)
|
||
|
@at-root #{selector.unify(&, $child)}
|
||
|
@content
|
||
|
|
||
|
|
||
|
.wrapper .field
|
||
|
@include unify-parent("input")
|
||
|
/* ... */
|
||
|
|
||
|
@include unify-parent("select")
|
||
|
/* ... */
|
||
|
===
|
||
|
.wrapper input.field {
|
||
|
/* ... */
|
||
|
}
|
||
|
|
||
|
.wrapper select.field {
|
||
|
/* ... */
|
||
|
}
|
||
|
{% endcodeExample %}
|