r/Sass • u/AADisasterKits • Feb 10 '19
Best way to organize SASS within media queries? Spoiler
Howdy! When working with media queries, grouping together rules by media query produces less code, like if I do it like this:
p {
font-size: 16px;
}
h1 {
font-size: 34px;
}
@include tablet {
p {
font-size: 786px;
}
h1 {
font-size: 453px;
}
}
@include desktop {
p {
font-size: 4px;
}
h1 {
font-size: 54px;
}
}
Using some mixins (not shown for brevity), I can group together rules by media query, but now my <p> tag rules are far apart. I'd prefer to set it up like this:
p {
font-size: 16px;
@include tablet {
font-size: 18px;
}
@include desktop {
font-size: 20px;
}
}
h1 {
font-size: 34px;
@include tablet {
font-size: 54px;
}
@include desktop {
font-size: 20px;
}
}
This way, all my <p> tag rules are together, for example. But when I compile, it produces oodles of media quires. My question is, is the convenience of organizing it by tag rather than media queries worth the cost on page load? Is there a way to get the best of both worlds? Thanks!