After testing the solution of colleagues I saw that there was a problem, which I believe is rendering, in Firefox, Edge and IE. As seen in the image
My solution was to use a SVG inline, in place of background-image
: This way with only a few lines it is possible to make a checkered background even easier to customize than the one made with linear-gradiente
, no request is made to the server, because the SVG
is inline and it was also possible to make a fallback with another backgraund
if the user’s browser does not support SVG. (recomendo que testem no IE caso tenham interesse para ver que ele usa o segundo URL como
background e ignora o primeiro)
Follow the basic result. Remember that you can easily change the size of the blocks by background-size
And the color of each square individually by fill
of rect
, Even within each square you can have a different gradient...
body {
background-image:
url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'>\
<rect fill='%23000' width='50' height='50' x='0' y='0' />\
<rect fill='%23000' width='50' height='50' x='50' y='50' />\
<rect fill='%23fff' width='50' height='50' x='50' y='0' />\
<rect fill='%23fff' width='50' height='50' x='0' y='50' />\
</svg>"),
url(https://abrilveja.files.wordpress.com/2018/01/mallandro.png);
background-size: 80px, cover;
}
Below a result shown the versatility of colors in bg if you want something different.
body {
background-image:
url("data:image/svg+xml;utf8,\
<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'>\
<defs>\
<linearGradient id='grad1' x1='0%' y1='0%' x2='100%' y2='0%'>\
<stop offset='0%' style='stop-color:rgb(255,255,0);stop-opacity:1' />\
<stop offset='100%' style='stop-color:rgb(255,0,0);stop-opacity:1' />\
</linearGradient>\
</defs>\
<rect fill='url(#grad1)' width='50' height='50' x='0' y='0' />\
<rect fill='black' width='50' height='50' x='50' y='50' />\
<rect fill='blue' width='50' height='50' x='50' y='0' />\
<rect fill='%23fff' width='50' height='50' x='0' y='50' />\
</svg>"),
url(https://abrilveja.files.wordpress.com/2018/01/mallandro.png);
background-size: 30px, cover;
}
EDITE:
New technique
New solution using mix-blend-mode
, but does not work in IE or EDGE, you can consult your browser support here https://caniuse.com/#feat=css-mix-blend-mode
The technique is to place two pseudo elements in body one ::before
and a ::after
and makes them the mix-blend-mode
along with a repeating-linear-gradient
. The blend mode difference
causes the overlapping colors to invert, so where there is a black line passing over the other black line at the intersection between them will be a "white square", generating this chessboard effect
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
position: relative;
}
body::before, body::after {
content:"";
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-image: repeating-linear-gradient(to right, #000 0, #000 40px, #fff 40px, #fff 80px);
}
body::after {
background-image: repeating-linear-gradient(to bottom, #000 0, #000 40px, #fff 40px, #fff 80px);
mix-blend-mode: difference;
}
a slight image with
repeat
would not look good?– Ricardo Pontual