<div class="grid-container">
<div class="grid-item gi-1">1</div>
<div class="grid-item gi-2">2</div>
<div class="grid-item gi-3">3</div>
</div>
/* CSS Reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
padding: 2%;
}
/* READ THIS:
Since we have set box-sizing to "border-box" on all HTML elements (see top of stylesheet), this means that the sum of the inner content, padding, and border will equal the total width and height of the item.
We set the border to 5px on all sides. This means that the border takes up 10px of space in both the height and width directions. Therefore, the total "available space" for grid items in this container is 300px in both directions.
310px - (5px + 5px) = 300px
Remember this as we go through the tutorial.
*/
.grid-container {
width: 310px;
height: 310px;
border: 5px solid #212226;
display: grid;
grid-template-rows: repeat(8, 1fr);
grid-template-columns: repeat(8, 1fr);
}
.gi-1 {
color: #1E4040;
background-color: #71D99E;
}
.gi-2 {
color: #71D99E;
background-color: #3A8C7D;
}
.gi-3 {
color: #71D99E;
background-color: #255954;
}
/*
Basic grid item styles. By using Flexbox, we can center the numbers in each grid item for aesthetic purposes.
You should be comfortable with these. If you aren't, please go back and take my basic CSS and Flexbox tutorials.
Basic CSS - https://bit.ly/39TbwrZ
Flexbox - https://bit.ly/3mcK9Oe
*/
.grid-item {
font-size: 2rem;
font-weight: 800;
display: flex;
align-items: center;
justify-content: center;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.