Skip to content

Instantly share code, notes, and snippets.

@alexparker
Created November 4, 2012 03:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexparker/4010097 to your computer and use it in GitHub Desktop.
Save alexparker/4010097 to your computer and use it in GitHub Desktop.
SASS Proposition for extending media queries via output buffer style functions
/*
I understand this is how it currently works.
Also there is a little "convenience" way to do it with some control structures and passing an argument to the mixin,
but the resulting code is still the same.
*/
@mixin handhelds() {
@media only screen and (max-width: 479px) { @content; }
}
.bluespace {
width: 800px;
height: 400px;
background-color: blue;
@include handhelds() {
width: 600px;
height: 300px;
}
}
.greenspace {
width: 300px;
height: 150px;
background-color: green;
@include handhelds() {
width: 200px;
height: 100px;
}
}
// ^ Generates this ...
.bluespace {
width: 800px;
height: 400px;
background-color: blue;
}
@media only screen and (max-width: 959px) { // <<== This is all good and well
.bluespace {
width: 600px;
height: 300px;
}
}
.greenspace {
width: 300px;
height: 150px;
background-color: green;
}
@media only screen and (max-width: 959px) { // <<== But then it gets duplicated & this is no good for the browser :(
.greenspace {
width: 200px;
height: 100px;
}
}
/*
Proposition:
I'm suggesting basically an output buffer that would allow a LOT of flexibility to block styles together.
I can see this immediately being helpful and effective for media queries. Especially for me personally.
Hopefully this makes sense enough to be self explanatory. I'm sure I'm not the first person to think about this
So maybe someone can answer as to why it might not be implemented yet?
*/
@buffer handhelds {
@media only screen and (max-width: 959px) {
@content;
}
}
.bluespace {
width: 800px;
height: 400px;
background-color: blue;
@append handhelds {
width: 600px;
height: 300px;
}
}
.greenspace {
width: 300px;
height: 150px;
@append handhelds {
width: 200px;
height: 100px;
}
}
@flush handhelds;
// Should Generate this ...
.bluespace {
width: 800px;
height: 400px;
background-color: blue;
}
.greenspace {
width: 300px;
height: 150px;
}
@media only screen and (max-width: 959px) {
.bluespace {
width: 600px;
height: 300px;
}
.greenspace {
width: 200px;
height: 100px;
}
}
@alexparker
Copy link
Author

Found a related feature request on Sass's issue tracking. Add you're vote, or implement it if you know how.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment