4

I am using compass. Is there any way to add !important to @include opacity(1)?

Thanks!

Srdjan Dejanovic
  • 1,267
  • 2
  • 18
  • 31

3 Answers3

5

Yes. You can use @if and @else

=opacity($opacity, $important: no)
    @if $important == isImportant
        opacity: $opacity !important
        $opacity-ie: $opacity * 100
        filter: alpha(opacity=$opacity-ie) !important //IE8
    @else
        opacity: $opacity
        $opacity-ie: $opacity * 100
        filter: alpha(opacity=$opacity-ie) //IE8


.some-class
    +opacity(1) // without !important

.some-class
    +opacity(1, isImportant) // with !important

if it is what u ment

Pavel
  • 412
  • 3
  • 6
  • just to note the slight syntactical difference in using SCSS, stumped me for a minute. http://stackoverflow.com/questions/5456467/syntax-for-if-else-condition-in-scss-mixin – sledgeweight Aug 14 '14 at 13:27
2

This is the same code in SCSS syntax, maybe someone can use it:

@mixin opacity($opacity, $important: 0) {
  @if $important == 1 {
    opacity: $opacity !important;
    $opacity-ie: $opacity * 100;
    filter: alpha(opacity=$opacity-ie) !important; //IE8
  }
  @else {
    opacity: $opacity;
    $opacity-ie: $opacity * 100;
    filter: alpha(opacity=$opacity-ie); //IE8
  }
}

.some-class
     @include opacity(1); // without !important

.some-class
     @include opacity(1,1); // with !important
0

A bit late, but this might be useful to someone out there. You could simply specify !important as part of the property value:

@include opacity(1 !important);

It might not work in every case depending on your mixin structure, but in most cases it should.