I tried to do the following, but it does not work:
* {
&::selection { text-decoration: underline; }
}
That's the way I do it:
// define it
@mixin selection {
::-moz-selection { @content; }
::selection { @content; }
}
// use it
@include selection {
color: white;
background: black;
}
I recommend to just use ::selection {}
with autoprefixer instead of a mixin. This will make your code thinner and your brain lighter :)
In this case, autoprefixer will transform this:
::selection {
color: white;
background: black;
}
...(depending on your target browsers/configuration) into something like that:
::-moz-selection {
color: white;
background: black;
}
::selection {
color: white;
background: black;
}
Mixins work with pseudo element selectors ;) see my mixin:
$prefixes: ("-moz-", "");
@mixin selection($color, $background) {
@each $prefix in $prefixes {
::#{$prefix}selection {
color: $color;
background: $background;
}
}
}
how to use:
@include selection(white, black);
of course you can make it far more flexible, but it was sufficient for me ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With