Let’s say I have a simple html CSS script:
<!DOCTYPE html>
<html>
<head>
<style>
.grid {
display: grid;
grid-template-columns: repeat(27, minmax(0, 1fr));
grid-template-rows: repeat(6, minmax(0, 1fr));
height: 50rem;
width: 50rem;
}
</style>
</head>
<body>
<div class="grid">
<!-- Your grid items will go here, but for this example, we're leaving them empty -->
</div>
</body>
</html>
I want the odd columns of the grid meaning 1,3,5,etc.. to be the color gray.
Notice that I don’t have any elements in the grid!
2
Answers
Use a gradient coloration:
To color odd columns of an empty CSS grid, you can use the :nth-child pseudo-class to target the grid items within the odd columns.
for Example:
In CSS,