Skip to content

Instantly share code, notes, and snippets.

@charlesroper
Created July 29, 2011 09:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesroper/1113547 to your computer and use it in GitHub Desktop.
Save charlesroper/1113547 to your computer and use it in GitHub Desktop.
Responsive Web Design with Sass (SCSS syntax)
@function pxem($pxval, $base: 16px) {
// Function to take a pixel value and divide it by a base value in order to
// return the size in ems. Default base value is 16px
@return ($pxval / $base) * 1em; // multiply by 1em to convert px to ems.
}
body {
background-color: #DCDBD9;
color: #2C2C2C;
font: normal 100% Cambria, Georgia, serif;
margin: pxem(40px); // 40px ÷ 16px = 2.5em
}
h1 {
font-size: pxem(24px); // 24px ÷ 16 = 1.5em
font-style: italic;
font-weight: normal;
}
h1 a {
color: #747474;
// The context is now 24px; i.e., the containing element -- h1 -- is 24px.
// So we divide by 24px instead of the default base value of 16px.
// 11px ÷ 24px = 0.458em
font: bold pxem(11px, 24px) Calibri, Optima, Arial, sans-serif;
letter-spacing: 0.15em;
text-transform: uppercase;
text-decoration: none;
}
/* This is the CSS emitted by the SCSS above */
body {
background-color: #DCDBD9;
color: #2C2C2C;
font: normal 100% Cambria, Georgia, serif;
margin: 2.5em;
}
h1 {
font-size: 1.5em;
font-style: italic;
font-weight: normal;
}
h1 a {
color: #747474;
font: bold 0.458em Calibri, Optima, Arial, sans-serif;
letter-spacing: 0.15em;
text-transform: uppercase;
text-decoration: none;
}
@agileapricot
Copy link

This appears to no longer work. I get an error saying...

Syntax error: 3.375em*px isn't a valid CSS value.

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