Skip to content

Instantly share code, notes, and snippets.

@contensis
Created April 28, 2014 09:20
Show Gist options
  • Save contensis/11366500 to your computer and use it in GitHub Desktop.
Save contensis/11366500 to your computer and use it in GitHub Desktop.
Working with CSS Files
' If the same URL is registered twice it will only output one reference.
' The URL is used as a key to prevent duplicates.
' Add a CSS file to the document head
CurrentContext.Page.CSS.Add("styles.css")
' Note on IEConditions: you can specify any version of IE, the examples below are used for illstration purposes and are not exhaustive
' Add a CSS file with an IECondition (target IE7)
CurrentContext.Page.CSS.Add("styles.css", IECondition.IsVersion(7))
' Add a CSS file with an IECondition (target IE9+)
CurrentContext.Page.CSS.Add("styles.css", IECondition.IsGreaterThanOrEqualTo(9))
' Add a CSS file with an IECondition (target IE)
CurrentContext.Page.CSS.Add("styles.css", IECondition.IsIE)
' Add a CSS file with an IECondition (target IE6 & IE7)
CurrentContext.Page.CSS.Add("styles.css", IECondition.IsLessThan(8))
' Add a CSS file with a media type
CurrentContext.Page.CSS.Add("styles.css", "print")
' Add a CSS file with an IE condition & media type
CurrentContext.Page.CSS.Add("styles.css", "print", IECondition.IsVersion(7))
' Add inline CSS
CurrentContext.Page.CSS.Add("body{background:#000;}")
' Add inline CSS with an IECondition
CurrentContext.Page.CSS.Add("body{background:#000;}", IECondition.IsVersion(7))
' Add inline CSS with a media type
CurrentContext.Page.CSS.Add("body{background:#000;}", "print")
' Add inline CSS with a media type and a IECondition
CurrentContext.Page.CSS.Add("body{background:#000;}", "print", IECondition.IsVersion(7))
' Remove a CSS file from the document
CurrentContext.Page.CSS.Remove("styles.css")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment