Skip to content

Instantly share code, notes, and snippets.

@wagerfield
Created February 27, 2013 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wagerfield/5047792 to your computer and use it in GitHub Desktop.
Save wagerfield/5047792 to your computer and use it in GitHub Desktop.
Ternary Operators in SASS. I stumbled across this great deck from @nickcooley covering the various features of SASS http://www.slideshare.net/nickcooley/advanced-sasscompass and wanted to create a quick Gist demonstrating the use of ternary operators in SASS.
// Example 1
@function theme($value)
@return if($value == "light", #FFFFFF, #000000)
background: theme("light") // Outputs #FFFFFF
background: theme("dark") // Outputs #000000
background: theme("cats") // Outputs #000000
// Example 2
@function even($value)
@return if($value % 2, "I'm odd.", "I'm even.")
content: event(0) // Outputs "I'm even."
content: event(1) // Outputs "I'm odd."
content: event(2) // Outputs "I'm even."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment