Last active
December 12, 2015 09:28
-
-
Save metaskills/4751248 to your computer and use it in GitHub Desktop.
Avoid universal selectors with a better box model in Sass/Compass.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inside my base include file which includes Compass. | |
%bs-border-box { @include box-sizing(border-box); } | |
// Inside my application Sass file. | |
@each $el in elements-of-type('block') { #{$el} { @extend %bs-border-box; } } | |
// Generates the following CSS. | |
address, article, aside, blockquote, center, dir, div, dd, details, dl, dt, | |
fieldset, figcaption, figure, form, footer, frameset, h1, h2, h3, h4, h5, h6, | |
hr, header, hgroup, isindex, menu, nav, noframes, noscript, ol, p, pre, | |
section, summary, ul { | |
-webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; | |
} |
Also, learn about Sass silent classes, called placeholder selectors, on Dale's speakerdeck presentation.
Is there any advantage to this approach over using the * selector?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Learn about
box-sizing: border-box
on Paul's blog post and then learn about Compass'elements-of-type
function from their source code on github.