I want to have a resposive checkerboard background that should look like the background in a color selector:
What I tried:
.chess {
background-image:
linear-gradient(90deg, #999 30px, white 30px),
linear-gradient(90deg, white 30px, #999 30px),
linear-gradient(90deg, #999 30px, white 30px),
linear-gradient(90deg, white 30px, #999 30px),
linear-gradient(90deg, #999 30px, white 30px),
linear-gradient(90deg, white 30px, #999 30px),
linear-gradient(90deg, #999 30px, white 30px);
background-position: 0 0, 0 30px, 0 60px, 0 90px, 0 120px;
background-repeat: repeat-x;
background-size: 60px 30px;
height: 150px;
margin: 15px auto;
width: 30%;
}
.fas {
text-align: center;
font-size: 10em
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.2/css/all.min.css" rel="stylesheet" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<div>
<div class="btn btn-outline-secondary chess">
<i class="fas fa-car"></i>
</div>
<div>
Problems:
- My result is not resposive. (I have fixed pixel sizes)
- I would need a lot of code if I have a larger background or smaller elements.
- I did not achieve to center the pattern or use
background-repeat: round
If it is possible I don't want any cut off elements in the checkerboard background.
Not like this (cut off on the right and bottom):
Here is an idea that rely on conic-gradient but supported only on Chrome actually:
You can also consider
round
ofbackground-repeat
if you want to have the same size and no cut off:Here is a similar idea using SVG instead of gradient where you will have better support:
And with a fixed size:
Not entirely sure on what you're trying to do, but I've created the following for you. This will fill whatever width your screen is with the checkered background, and not be cut off on smaller screens.
JSFiddle
Use this:
OR you can use pattern image like: