CSS gradient checkerboard pattern

后端 未结 5 1998
夕颜
夕颜 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:38

    The 45deg version works nicely, but can end up showing a line between the triangles at different zoom levels or on retina screens. Depending on what browsers you need to support you can also use background-blend-mode: difference (caniuse currently shows nearly 90% support), you can tint the checks using an additional background image:

    body {
        background-image: /* tint image */
                          linear-gradient(to right, rgba(192, 192, 192, 0.75), rgba(192, 192, 192, 0.75)),
                          /* checkered effect */
                          linear-gradient(to right, black 50%, white 50%),
                          linear-gradient(to bottom, black 50%, white 50%);
        background-blend-mode: normal, difference, normal;
        background-size: 2em 2em;
    }

提交回复
热议问题