An attempt to create optical illusions with CSS and JS. Wikipedia link
We could achieve this by placing a number of square div elements inside a container div with uniform spacing.
ImplementationAdd a container div with relatively large width and height. Append a series of square divs via a JS function as children to the container div. A div is a block element hence it should be arranged inline. We can accomplish this in two ways:
display: inline-block'
on individual divs.
display: flex; flex-wrap: wrap;
on the container div.
var hermann = document.getElementById('hermann-grid');
var hermannSquare = document.createElement('div');
hermannSquare.className = "hermann-square";
hermann.appendChild(hermannSquare);
CSS gotcha:
When using display: inline-block'
, you run into this gotcha that adds some extra space inbetween the divs. Use flexbox to avoid it.