SASS: content block mixin (or placeholder) that takes contextual selectors and appends them to selector in mixin
You just need to move the &
to be part of the mixin:
@mixin context($size) {
body.#{$size} & {
@content
}
}
div {
span {
font-size: 2em;
@include context('large') {
font-size: 5em;
}
}
}
Output:
div span {
font-size: 2em;
}
body.large div span {
font-size: 5em;
}
As of Sass 3.4, you can write this to work both inside a selector and at the root of the document:
@mixin optional-at-root-nest($sel) {
@at-root #{if(not &, $sel, selector-nest($sel, &))} {
@content;
}
}
@mixin context($size) {
@include optional-at-root-nest('body.#{$size}') {
@content
}
}
div {
span {
font-size: 2em;
@include context('large') {
font-size: 5em;
}
}
}
@include context('large') {
font-size: 2em;
}
SASS: How to declare inline browser-dependent overrides?
You can just just &
to do this:
.selector {
font: 'Arial';
font-weight: 400;
.ie7 & {
font-weight: 500;
}
}
Just write the .SCSS as .ie7 &
and Sass will interpret that as a container:
.selector {
font: 'Arial';
font-weight: 400;
}
.ie7 .selector {
font-weight: 500;
}
Related Topics
The CSS Selector for an Element That Its Id Is in The "Foo:Bar" Form
Flying-Saucer/Itext PDF in Servlet Not Finding CSS File
CSS Layout Help - Stretch Div to Bottom of Page
Brightness Filter in Firefox and Opera Without Svg File
Performance of Jquery Selectors Vs CSS3 Selectors
Iframe Z-Index for Drop Down Menu
Adding Dynamic Class Name in Svelte
Rotate Child Element Around The Parent Element with Transition
Asp.Net Mvc: How to Use Razor Variable in CSS File
CSS "Height: [Percentage]" Behaviour Using "Margin" And/Or "Padding"
Can The SASS Minifier Remove Duplicate Styles
How to Get CSS Pseudo Element: Checked to Work in Ie7 + Ie8
CSS3 Onclick Activate Another Div's Animation
How to Horizontally Center-Crop Div Inside Other Div
How to Use CSS to Reverse The Display Order of Two Elements