2018-09-01 13:35:20 -07:00
|
|
|
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
|
2019-09-02 16:32:14 -07:00
|
|
|
uses the [`selector.unify()` function][] to combine `&` with a user's selector.
|
2018-09-01 13:35:20 -07:00
|
|
|
|
2019-09-02 16:32:14 -07:00
|
|
|
[`selector.unify()` function]: ../modules/selector#unify
|
2018-09-01 13:35:20 -07:00
|
|
|
|
|
|
|
<% example do %>
|
2019-09-02 16:32:14 -07:00
|
|
|
@use "sass:selector";
|
|
|
|
|
2018-10-23 13:42:40 -07:00
|
|
|
@mixin unify-parent($child) {
|
2019-09-02 16:32:14 -07:00
|
|
|
@at-root #{selector.unify(&, $child)} {
|
2018-10-23 13:42:40 -07:00
|
|
|
@content;
|
|
|
|
}
|
2018-09-01 13:35:20 -07:00
|
|
|
}
|
|
|
|
|
2018-10-23 13:42:40 -07:00
|
|
|
.wrapper .field {
|
|
|
|
@include unify-parent("input") {
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
@include unify-parent("select") {
|
|
|
|
/* ... */
|
|
|
|
}
|
2018-09-01 13:35:20 -07:00
|
|
|
}
|
2018-10-23 13:42:40 -07:00
|
|
|
===
|
2019-09-02 16:32:14 -07:00
|
|
|
@use "sass:selector";
|
|
|
|
|
2018-10-23 13:42:40 -07:00
|
|
|
@mixin unify-parent($child)
|
2019-09-02 16:32:14 -07:00
|
|
|
@at-root #{selector.unify(&, $child)}
|
2018-10-23 13:42:40 -07:00
|
|
|
@content
|
2018-09-01 13:35:20 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-23 13:42:40 -07:00
|
|
|
.wrapper .field
|
|
|
|
@include unify-parent("input")
|
|
|
|
/* ...
|
2018-09-01 13:35:20 -07:00
|
|
|
|
2018-10-23 13:42:40 -07:00
|
|
|
@include unify-parent("select")
|
|
|
|
/* ...
|
2019-09-02 16:32:14 -07:00
|
|
|
===
|
|
|
|
.wrapper input.field {
|
|
|
|
/* ... */
|
|
|
|
}
|
|
|
|
|
|
|
|
.wrapper select.field {
|
|
|
|
/* ... */
|
|
|
|
}
|
2018-09-01 13:35:20 -07:00
|
|
|
<% end %>
|