I'm trying to define the heights of elements as a function of the size of the screen width being called in the @media function. I want this function to have a multiplier, so that each element can have a custom height relative to it's width on the screen, across all possible breakpoints. This is my first attempt at a custom function.
I know I'm missing some important elements in the design. Though I am familiar with the concepts of SASS I am lacking executive prowess, therefore I don't know what's missing/wrong.
My breakpoints:
$breakpoints:(
'micro' : (min-width: 320px),
'mobile' : (min-width:600px),
'small' : (min-width: 767px ),
'medium' : (min-width: 992px ),
'large' : (min-width: 1200px )
);
My boilerplate breakpoint mixin:
@mixin respond-to($name){
//If the key exists in the map
@if map-has-key($breakpoints, $name){
// Prints a media query based on the value
@media #{inspect(map-get($breakpoints, $name))}{
@content;
}
}
// If the key doesn't exist in the map
@else{
@warn "Unfortunately, no value could be retrieved from '#(breakpoint}`."
+ "Please make sure it is defined in `$breakpoints` map.";
}
}
Those things were pulled from a web tutorial. I quickly realized that I would have very ugly sass code if I write out and edit the respond-to mixin 6 times in every single one of the classes.
I want to be able to handle all of my breakpoints simultaneously, with a single @include
so that I can throw together a responsive website quickly. I can tweak individual elements seperately after I've got my idea out.
My objective as mentioned in the first paragraph is to create a height($multiplier) mixin where an input number $multiplier is multiplied by the interger in whatever particular $breakpoint is being called in the calculation.
Do I need to call the map again? Or is calling the mixin 'respond-to' sufficient?
//HERO HEIGHT
//remember to check that the length of the str slice matches the length
//of the value in $breakpoint map.
@mixin height($multiplier){
@include respond-to('micro'){
height: str-slice($name,12,15)*$multipler;
}
@include respond-to('mobile'){
height: str-slice($name,12,15)*$multiplier ;
}
@include respond-to('small'){
height: str-slice($name,12,15)*$multiplier ;
}
@include respond-to('medium'){
height: str-slice($name,12,15)*$multiplier ;
}
@include respond-to('large'){
height: str-slice($name,12,16)*$multiplier;
}
}
.mainhero{
//@include span(full);
@include height(1.25);
background: {
image: url("images/executive communication.jpg");
repeat: no-repeat;
attachment: fixed;
size: cover;
position: center;
}
}