I am working with a partial file named _display.scss
.
It includes various @mixin
and styling classes related to the display CSS property.
_display.scss
@mixin d-block{
display: block;
}
@mixin d-none{
display: none;
}
.d-block{
@include d-block();
}
.d-none{
@include d-none();
}
I have also created a @mixin
called generate-responsive-content, which takes the @content
of a class and generates different @media queries for each breakpoint.
For example:
.d-block{
@include generate-responsive-content() {
@include d-block();
}
}
.d-none{
@include generate-responsive-content() {
@include d-none();
}
}
// Generate all breakpoints from content
@mixin generate-responsive-content() {
// Responsive styles
// Loop over each size
@each $breakName, $width in $breakpoints {
// Check breakpoint
@if ($breakName != "") {
$breakName: '-' + $breakName;
@media (min-width: $width) {
&#{$breakName} {
@content
}
}
} @else {
@content;
}
}
}
For instance, classes like: .d-block
, .d-block-xs
, .d-block-sm
...
However, I encountered an issue where I cannot override the classes of .d-none
with the classes of .d-block
for each breakpoint because they are generated earlier and get overwritten by those of .d-none
.
In addition, there are classes with the same name but without breakpoint variants, such as d-none-lg
, d-block-lg
, which take precedence over others.
You can view a demonstration on this CodePen. Here, d-none
variants overwrite every class of d-block
.
How can I resolve this conflict?