Sass - Converting Hex to RGBa for background opacity

后端 未结 5 1834
迷失自我
迷失自我 2020-12-12 09:40

I have the following Sass mixin, which is a half complete modification of an RGBa example:

@mixin ba         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-12 10:05

    you can try this solution, is the best... url(github)

    // Transparent Background
    // From: http://stackoverflow.com/questions/6902944/sass-mixin-for-background-transparency-back-to-ie8
    
    // Extend this class to save bytes
    .transparent-background {
      background-color: transparent;
      zoom: 1;
    }
    
    // The mixin
    @mixin transparent($color, $alpha) {
      $rgba: rgba($color, $alpha);
      $ie-hex-str: ie-hex-str($rgba);
      @extend .transparent-background;
      background-color: $rgba;
      filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=#{$ie-hex-str},endColorstr=#{$ie-hex-str});
    }
    
    // Loop through opacities from 90 to 10 on an alpha scale
    @mixin transparent-shades($name, $color) {
      @each $alpha in 90, 80, 70, 60, 50, 40, 30, 20, 10 {
        .#{$name}-#{$alpha} {
          @include transparent($color, $alpha / 100);
        }
      }
    }
    
    // Generate semi-transparent backgrounds for the colors we want
    @include transparent-shades('dark', #000000);
    @include transparent-shades('light', #ffffff);
    

提交回复
热议问题