Imagine we have a stylesheet with two classes, a and b, each with styles changing at a certain breakpoint:
.a {
//styles
}
.b {
//styles
}
@media (max-width: 768px) {
.a {
//mobile styles
}
.b {
//mobile styles
}
}
These are grouped by breakpoint. Is it ever preferred to group them by selector instead? i.e:
.a {
//styles
}
@media (max-width: 768px) {
.a {
//styles
}
}
.b {
//styles
}
@media (max-width: 768px) {
.b {
//styles
}
}
The second looks a bit uglier, but that could easily be corrected with scss nested media queries. My concern with the former pattern is that it can encourage developers to edit one section of styles without taking a look at how a style change may affect its counterparts at other breakpoints. However, the former may be more useful for developers working on problems that appear only at specific screen sizes.
Would love to hear any thoughts or schools of thought with regard to this conflict of grouping - I've been looking for any resources on Smashing Magazine or CSS tricks but haven't come up with anything.
After doing ample research, I've personally arrived at this answer