Great question! LESS mixins can do a lot of things that CSS variables alone cannot, especially when it comes to nested selectors and complex rules. However, you can replicate the values part of your mixin using CSS variables, but not the nested selectors or structure.
What your LESS mixin does:
.editing-mixin() {
background-color: #cec952;
border-color: #aa3;
color: black;
.red {
color: #9a0000;
}
.blue {
color: #1048ff;
}
& > header, & > figcaption {
a, b:not(.admin):not(.sage) {
color: #222;
}
}
& > .post-container > blockquote, & > .backlinks {
& > em > a, & > a {
color: #222;
}
& > em {
color: #656d28;
}
}
code.code-tag {
background: #222;
}
}
What CSS variables can do:
CSS variables can store values like colors, but cannot store selectors or nested rules.
How to replicate the values as CSS variables:
Define variables for the colors:
:root {
--editing-bg-color: #cec952;
--editing-border-color: #aa3;
--editing-color: black;
--editing-red-color: #9a0000;
--editing-blue-color: #1048ff;
--editing-link-color: #222;
--editing-em-color: #656d28;
--editing-code-bg: #222;
}
How to use these variables in CSS:
You still need to write the selectors explicitly, but use the variables for colors:
.editing {
background-color: var(--editing-bg-color);
border-color: var(--editing-border-color);
color: var(--editing-color);
}
.editing .red {
color: var(--editing-red-color);
}
.editing .blue {
color: var(--editing-blue-color);
}
.editing > header a,
.editing > header b:not(.admin):not(.sage),
.editing > figcaption a,
.editing > figcaption b:not(.admin):not(.sage) {
color: var(--editing-link-color);
}
.editing > .post-container > blockquote > em > a,
.editing > .post-container > blockquote > a,
.editing > .backlinks > em > a,
.editing > .backlinks > a {
color: var(--editing-link-color);
}
.editing > .post-container > blockquote > em,
.editing > .backlinks > em {
color: var(--editing-em-color);
}
.editing code.code-tag {
background: var(--editing-code-bg);
}
Summary:
- LESS mixins can bundle selectors and styles together.
- CSS variables only store values, not selectors or nested rules.
- You can replace the color values with CSS variables for easier theming.
- You still need to write the full CSS selectors explicitly.
If you want, I can help you generate a full CSS snippet using variables based on your LESS mixin! Would you like that?