I have a CSS grid that represents the tic-tac-toe game. I wanted to put an border only inside the grid. Today, I proceed in this way:
:root {
--border: 2px dashed #393939;
--symbol-color: #FF7F5B;
}
.grid {
height: 100%;
display: grid;
grid-template-columns: repeat(3, calc(100%/3));
grid-template-rows: repeat(3, calc(100%/3));
}
.child {
display: flex;
align-items: center;
align-content: center;
color: var(--symbol-color);
font-size: 2.5rem;
}
.child:nth-child(1),
.child:nth-child(2),
.child:nth-child(3) {
border-bottom: var(--border);
}
.child:nth-child(7),
.child:nth-child(8),
.child:nth-child(9) {
border-top: var(--border);
}
.child:nth-child(1),
.child:nth-child(4),
.child:nth-child(7) {
border-right: var(--border);
}
.child:nth-child(3),
.child:nth-child(6),
.child:nth-child(9) {
border-left: var(--border);
}
<div class="grid">
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
<div class="child"></div>
</div>
Result:
This solution works but I find it unattractive. Do you have an idea to refactor this solution?
align-content
flex container property. I guess you meantjustify-content
. – Indrawn