Answer the question
In order to leave comments, you need to log in
Is it possible to make such a mixin for scss?
Positioning is used many times in .scss project styles, for example:
.block{
position: relative;
top: 20px;
left: - 45px;
}
.logo{
position: relative;
span{
position: absolute;
top: -30px;
right: 20px;
}
}
@mixin position($position, $top, $right, $bottom, $left){
position: $position;
top: $top;
right: $right;
bottom: $bottom;
left: $left;
}
.block{
@include position(relative, 20px, 0, 0, -45px);
}
Answer the question
In order to leave comments, you need to log in
You can. But to shorten the final css, I would add an if to the mixin so that only the values that are needed would be displayed:
@mixin position($position, $top, $right, $bottom, $left){
position: $position;
@if($top!=null){
top: $top;
}
@if($right!=null){
right: $right;
}
@if($bottom!=null){
bottom: $bottom;
}
@if ($left!=null){
left: $left;
}
}
.block{
@include position(relative, 20px, null, null, -45px);
}
Not at all, for indefinite positions, you need to set the value to "auto".
PS IMHO, such a mixin is not needed. It does not simplify, but even complicates the addition of position
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question