Is something like the following dummyexample possible in sass/scss? I need something like this to prevent the endless mediaquery repeats for different devices.
// The dummy mixin
@mixin iphone_rules($webapp_portrait:null){
@if($webapp_portrait != null){
// Portrait (webapp)
@media screen and (max-height: 460px){
// The following line is just a dummy
eg. echo $webapp_portrait;
}
}
}
// How I want to use it
.mySelector{
margin-left:10px;
padding:0px;
@include iphone_rules('margin-left:20px; padding:2px;');
}
Variable argument is used to pass any number of arguments to mixin. It contains keyword arguments passed to the function or mixin. Keyword arguments passed to the mixin can be accessed using keywords($args) function which return values mapped to String.
The keyword arguments are used to include in mixins. It specifies that the named arguments can be passed in any order and the default value of arguments can be omitted.
CSS mixinsAny CSS stylesheet, class or element that is defined in a Stylable CSS file can be used as a mixin source. You can use either a local class or element, or import the mixin from a different stylesheet. In the following example, a locally defined class is used as a mixin in the same stylesheet.
Sass does not allow the use of arbitrary strings in place of the property/value syntax.
For most mixins, the @content
directive is your best bet for passing in styling information:
@mixin iphone_rules {
@media screen and (max-height: 460px){
@content;
}
}
.mySelector {
@include iphone_rules {
margin-left:10px;
padding:0px;
}
}
Otherwise, styling information can be passed in as a mapping (or list of lists for Sass 3.2 and older):
@mixin iphone_rules($styles: ()) {
@media screen and (max-height: 460px){
@each $p, $v in $styles {
#{$p}: $v;
}
}
}
.mySelector {
margin-left:10px;
padding:0px;
@include iphone_rules(('margin-left': 20px, 'padding': 2px));
}
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