sass-site/source/code-snippets/_example-advanced-nesting.html.md.erb
coskunuyar 8e97e71e66
Invalid Examples (#451)
* Fix invalid semicolon on SASS example
* Fix wrong argument reference
* Fix invalid assignment to variable due to scope
2020-06-01 10:31:10 -07:00

48 lines
919 B
Plaintext

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
<% example do %>
@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 {
/* ... */
}
<% end %>