Skip to content

Instantly share code, notes, and snippets.

@Snugug
Created April 20, 2012 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Snugug/2430123 to your computer and use it in GitHub Desktop.
Save Snugug/2430123 to your computer and use it in GitHub Desktop.

Sass

%half { width: 50%; }
%full { width: 100%; }

#foo {
  @extend %full;

  @media screen (min-width: 600px) {
    @extend %half;
  }
}

#bar {
  @extend %full;
}

#baz {
  @extend %half;
}

CSS

#foo, #bar {
  width: 100%;
}

@media screen and (min-width: 600px) {
  #foo {
    width: 50%;
  }
}

#baz {
  width: 50%;
}
@scottkellum
Copy link

Forked here to apply markdown styling and SCSS highlights: https://gist.github.com/2431779
Gist tied to discussion here: sass/sass#154

The point is really about extending silent selectors, not classes. @extend when used poorly does generate a lot of really ugly code but when paired with silent selectors and used cleanly it can dramatically reduce file size.

Extends in browser won’t work because the original selectors are never written to CSS. The idea is to abstract these objects away from the CSS so they never see the browser. sass/sass#96 (comment)

@Snugug
Copy link
Author

Snugug commented Apr 20, 2012

Now why the hell didn't that frickin work for me? Really need to figure out the Gist stuff on Github

@scottkellum
Copy link

in file name make it .md or .markdown :)

@Snugug
Copy link
Author

Snugug commented Apr 20, 2012

Genius!

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