Skip to content

Instantly share code, notes, and snippets.

@nucliweb
Created September 26, 2014 18:13
Show Gist options
  • Save nucliweb/2307d5baddaaa1f4dea0 to your computer and use it in GitHub Desktop.
Save nucliweb/2307d5baddaaa1f4dea0 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.4.4)
// Compass (v1.0.1)
// ----
/// Bind all events, including self state if `$self` is true.
/// @author Harry Roberts
/// @link https://github.com/csswizardry/csswizardry.github.com/blob/master/css/_tools.mixins.scss#L13 CSSWizardry
/// @param {Bool} $self - Include self state
/// @output `:hover`, `:active` and `:focus`
@mixin on-event($self: false) {
// If $self is truthy, include self state
@if $self {
&, &:hover, &:active, &:focus { @content }
}
@else {
&:hover, &:active, &:focus { @content }
}
}
/// Define a context for the current selector
/// @author Hugo Giraudel
/// @param {String} $context - Context
/// @output `#{$context} & { ... }`
@mixin context($context) {
#{$context} & {
@content;
}
}
// `on-event` test
element {
opacity: 1;
@include on-event {
opacity: .5;
}
}
// `context` test
element {
opacity: 0;
@include context('.no-opacity') {
visibility: hidden;
}
}
// You can also mix and match
// Although I would not recommend this
// since it can hurt readability.
element {
@include context('.no-opacity') {
visibility: hidden;
@include on-event {
visibility: visible;
}
}
}
element {
opacity: 1;
}
element:hover, element:active, element:focus {
opacity: .5;
}
element {
opacity: 0;
}
.no-opacity element {
visibility: hidden;
}
.no-opacity element {
visibility: hidden;
}
.no-opacity element:hover, .no-opacity element:active, .no-opacity element:focus {
visibility: visible;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment