Skip to content

Instantly share code, notes, and snippets.

@vkemeter
Created December 19, 2018 14:10
Show Gist options
  • Save vkemeter/a40af68b9e90596176f49ec2c904c43e to your computer and use it in GitHub Desktop.
Save vkemeter/a40af68b9e90596176f49ec2c904c43e to your computer and use it in GitHub Desktop.
SCSS Font-Size Idea
// use sass iteration to set class for every
// element in different breakpoints
// with different styles
@each $elem in map-keys($test) {
#{$elem} {
@each $breakpoint, $style in _get($test, $elem) {
@include media-breakpoint-up(#{$breakpoint}) {
@each $k, $v in _get($test, $elem $breakpoint) {
#{$k}: #{$v};
}
}
}
}
}
// set array with every element wich could have different font sizes
// than a global used font-size
$test: (
'.test': (
'xs': (
'font-size': 14px,
'line-height': 1.2,
'margin-bottom': 18px,
),
'md': (
'font-size': 16px,
'line-height': 1.5,
'margin-bottom': 20px,
),
'xl': (
'font-size': 18px,
'line-height': 1.8,
'margin-bottom': 22px,
),
)
);
/* should result in this */
.test {
font-size: 14px;
line-height: 1.2;
margin-bottom: 18px;
}
@media (min-width: 768px) {
.test {
font-size: 16px;
line-height: 1.5;
margin-bottom: 20px;
}
}
@media (min-width: 1200px) {
.test {
font-size: 18px;
line-height: 1.8;
margin-bottom: 22px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment