Created
September 30, 2011 09:54
-
-
Save janogarcia/1253308 to your computer and use it in GitHub Desktop.
Translucent background colors in IE for Twitter Bootstrap
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
// Extension to Twitter Bootstrap's mixin.less that adds support for translucent background colors in IE6-IE9 (deprecated as of IE9) | |
#translucent { | |
.background(@color: @white, @alpha: 1) { | |
// http://css3please.com/ | |
// http://msdn.microsoft.com/en-us/library/ms532997(v=vs.85).aspx | |
background-color: transparent; | |
background-color: hsla(hue(@color), saturation(@color), lightness(@color), @alpha); | |
// http://stackoverflow.com/questions/2877322/convert-opacity-to-hex-in-javascript | |
// http://robertnyman.com/2010/01/11/css-background-transparency-without-affecting-child-elements-through-rgba-and-filters/ | |
@alphaHex: `Math.floor(@{alpha} * 255).toString(16)`; | |
@colorIE: `"@{color}".replace(/#/, "#"+@{alphaHex})`; | |
filter: ~`'progid:DXImageTransform.Microsoft.gradient(startColorstr=@{colorIE},endColorstr=@{colorIE})'`; | |
zoom: 1; | |
} | |
.border(@color: @white, @alpha: 1) { | |
border-color: hsla(hue(@color), saturation(@color), lightness(@color), @alpha); | |
background-clip: padding-box; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment