Dia 10/2019 - Calendário com CSS Grid

Desafio #92daysofcode que fiz no final de 2019. Nesse artigo temos o dia 10, mostrando o uso da pseudo-classe :nth-of-type().

Pré-visualização

Código

Começamos com a estrutura do HTML.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Day 10</title>
<style>
*, *:before, *:after { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing:border-box; }
html { -webkit-box-sizing:border-box; -moz-box-sizing:border-box; box-sizing:border-box; }
* { margin: 0; padding: 0; list-style: none; }
body { background: #eee; font-family: Arial, Helvetica, sans-serif; }
</style>
<link rel="stylesheet" type="text/css" href="./day-10.css">
</head>
<body>
<div class="container">
<!-- calendar -->
</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<header class="header">
<h1 class="header-title">October</h1>
<p class="header-text">2019</p>
</header>
<main class="calendar">
<span class="dayOfTheWeek">Mon</span>
<span class="dayOfTheWeek">Tue</span>
<span class="dayOfTheWeek">Wed</span>
<span class="dayOfTheWeek">Thu</span>
<span class="dayOfTheWeek">Fri</span>
<span class="dayOfTheWeek">Sat</span>
<span class="dayOfTheWeek">Sun</span>

<div class="day day--disabled">29</div>
<div class="day day--disabled">30</div>

<div class="day">1</div>
<div class="day">2</div>
<div class="day">3</div>
<div class="day">4</div>
<div class="day">5</div>
<div class="day">6</div>
<div class="day">7</div>
<div class="day">8</div>
<div class="day">9</div>
<div class="day">10</div>
<div class="day">11</div>
<div class="day">12</div>
<div class="day">13</div>
<div class="day">14</div>
<div class="day">15</div>
<div class="day">16</div>
<div class="day">17</div>
<div class="day">18</div>
<div class="day">19</div>
<div class="day">20</div>
<div class="day">21</div>
<div class="day">22</div>
<div class="day">23</div>
<div class="day">24</div>
<div class="day">25</div>
<div class="day">26</div>
<div class="day">27</div>
<div class="day">28</div>
<div class="day">29</div>
<div class="day">30</div>
<div class="day">31</div>

<div class="day day--disabled">1</div>
<div class="day day--disabled">2</div>

<section class="item item--warning">Project 1</section>
<section class="item item--info">Project 2</section>
<section class="item item--danger">Project 3</section>
</main>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
.container {
box-shadow: 0 1px 4px #cacaca;
border-radius: 4px;
background: #fff;
margin: 10px auto;
max-width: 992px;
overflow: hidden;
width: 90%;
}

.header { background: #fafbfd; border-bottom: 1px solid #e0e0e0; padding: 20px 0; text-align: center; }

.header-title { font-size: 20px; }

.header-text { color: #999; font-size: 12px; font-weight: 700; margin-top: 5px; }

.calendar {
display: grid;
width: 100%;
grid-template-columns: repeat(7, minmax(120px, 1fr));
grid-template-rows: 50px;
grid-auto-rows: 120px;
overflow: auto;
}

.day {
border-bottom: 1px solid #e0e0e0;
border-right: 1px solid #e0e0e0;
box-sizing: border-box;
color: #98a0a6;
font-size: 12px;
letter-spacing: 1px;
padding: 14px 20px;
position: relative;
pointer-events: none;
text-align: right;
z-index: 1;
}

.day:nth-of-type(7n + 7) { border-right: 0; }
.day:nth-of-type(n + 1):nth-of-type(-n + 7) { grid-row: 2; }
.day:nth-of-type(n + 8):nth-of-type(-n + 14) { grid-row: 3; }
.day:nth-of-type(n + 15):nth-of-type(-n + 21) { grid-row: 4; }
.day:nth-of-type(n + 22):nth-of-type(-n + 28) { grid-row: 5; }
.day:nth-of-type(n + 29):nth-of-type(-n + 35) { grid-row: 6; }
.day:nth-of-type(7n + 1) { grid-column: 1/1; }
.day:nth-of-type(7n + 2) { grid-column: 2/2; }
.day:nth-of-type(7n + 3) { grid-column: 3/3; }
.day:nth-of-type(7n + 4) { grid-column: 4/4; }
.day:nth-of-type(7n + 5) { grid-column: 5/5; }
.day:nth-of-type(7n + 6) { grid-column: 6/6; }
.day:nth-of-type(7n + 7) { grid-column: 7/7; }

.dayOfTheWeek {
border-bottom: 1px solid #e0e0e0;
color: #99a1a7;
font-size: 12px;
font-weight: 500;
line-height: 50px;
text-transform: uppercase;
text-align: center;
}

.day--disabled { background-color: #f1f1f1; color: #ccc; cursor: not-allowed; }

.item {
border-left-style: solid;
border-left-width: 3px;
margin: 10px;
font-size: 14px;
padding: 8px 12px;
position: relative;
}

.item--warning {
align-self: center;
background: #fbfedb;
border-left-color: #fffe01;
color: #d8be00;
grid-column: 4 / span 3;
grid-row: 3;
margin-top: -5px;
}

.item--danger {
align-self: end;
background: #ffd5de;
border-left-color: #fa607e;
color: #f8254e;
grid-column: 2 / span 2;
grid-row: 5;
margin-top: 15px;
}

.item--info {
align-self: end;
background: #e7fdff;
border-left-color: #4786ff;
color: #0a5eff;
grid-column: 2 / span 3;
grid-row: 3;
margin-top: 15px;
}

Conclusão

A postagem original pode ser vista no meu Instagram e o código está acessível no meu Github.

Ao fechar este aviso ou continuar navegando no site Nerd Calistênico, você aceita o uso de cookies.

Este site usa cookies para assegurar a melhor experiência para os nossos usuários. Consulte nossa política de privacidade.

Uma nova versão está disponível. Clique aqui para atualizar.