CSS gradient checkerboard pattern

后端 未结 5 1997
夕颜
夕颜 2020-12-14 00:09

I want to create a checkerboard pattern using gradients. I\'ve found an example and modified it to my needs, however it only works with -moz prefix. When I remo

5条回答
  •  醉酒成梦
    2020-12-14 00:30

    Thanks Harry for the inspiration - here's an scss mixin to do that

    @mixin checkers($size: 50px, $contrast: 0.07) {
      $checkerColor: rgba(#000, $contrast);
      $angle: 45deg;
      $tp: 25%;
    
      background-image: linear-gradient($angle, $checkerColor $tp, transparent $tp),
        linear-gradient(-$angle, $checkerColor $tp, transparent $tp),
        linear-gradient($angle, transparent 3 * $tp, $checkerColor 3 * $tp),
        linear-gradient(-$angle, transparent 3 * $tp, $checkerColor 3 * $tp);
      background-size: $size $size;
      background-position: 0 0, 0 $size/2, $size/2 -1 * $size/2, -1 * $size/2 0;
    }
    

提交回复
热议问题