Created
July 21, 2019 09:21
-
-
Save ErnWong/847dedc5c973a6d2dac372c55fb06dd1 to your computer and use it in GitHub Desktop.
Zigzag CSS pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateZigZag(size, thickness) { | |
const ratio = (thickness / size / 2) * 100; | |
const quadrantMain = `transparent ${25 - ratio}%, black ${25 - ratio}%, black 25%, transparent 25%`; | |
const quadrantTip = `black ${ratio}%, transparent ${ratio}%`; | |
return { | |
background: [ | |
`linear-gradient(-45deg, ${quadrantTip}) ${-size}px ${size}px`, | |
`linear-gradient(-45deg, ${quadrantTip}) 0 ${size}px`, | |
`linear-gradient(-135deg, ${quadrantTip}) ${-size}px ${-size}px`, | |
`linear-gradient(-135deg, ${quadrantTip}) 0 ${-size}px`, | |
`linear-gradient(135deg, ${quadrantMain}) 0 0`, | |
`linear-gradient(135deg, ${quadrantMain}) ${size}px 0`, | |
`linear-gradient(45deg, ${quadrantMain}) 0 0`, | |
`linear-gradient(45deg, ${quadrantMain}) ${size}px 0`, | |
].join(', '), | |
backgroundSize: `${2 * size}px ${2 * size}px`, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment