Tiles in Grid in CSS
Let's move on to practical work with the grid system and create tiles with different indents.
Tiles of 9 blocks, 3 in a row, without indentation
Let's create a table with nine elements and arrange them into three columns:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
</div>
#parent {
display: grid;
grid-template-columns: repeat(3, 1fr);
border: 2px solid #696989;
padding: 10px;
width: 600px;
}
#parent > div {
height: 100px;
padding: 10px;
border: 1px solid #696989;
}
:
Tiles of 9 blocks, 3 in a row with indents
Now let's apply the grid-gap
property to create some space between the elements:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
</div>
#parent {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
border: 2px solid #696989;
padding: 10px;
width: 600px;
}
#parent > div {
height: 100px;
padding: 10px;
border: 1px solid #696989;
}
:
Tiles of 9 blocks, 3 in a row, with spaces only between blocks
Now let's set the distance only between blocks in the grid:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
</div>
#parent {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
border: 2px solid #696989;
width: 600px;
}
#parent > div {
height: 100px;
padding: 10px;
border: 1px solid #696989;
}
:
A tile of 8 blocks, 3 in a row, with a missing block
Let's make a tile where one block is missing in the bottom row:
<div id="parent">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
#parent {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
border: 2px solid #696989;
width: 600px;
}
#parent > div {
height: 100px;
padding: 10px;
border: 1px solid #696989;
}
:
Practical tasks
Implement the following example:
Implement the following example:
Implement the following example: