<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CSS Grid</title>
<style>
body {
font-family: sans-serif;
}
.grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, minmax(150px, auto));
gap: 10px;
width: 400px;
margin: 20px 0;
/* Wartość domyślna - odkomentuj kolejne linie jedną po drugiej
aby zaobserwować różnice w wertykalnym położeniu elementu. */
align-items: stretch;
/* align-items: start; */
/* align-items: end; */
/* align-items: center; */
}
.grid.justify {
/* Wartość domyślna - odkomentuj kolejne linie jedną po drugiej
aby zaobserwować różnice w horyzontalnym położeniu elementu. */
justify-items: stretch;
/* justify-items: start; */
/* justify-items: end; */
/* justify-items: center; */
}
.grid.both {
/* Właściwości te oczywiście możemy ze sobą łączyć. */
align-items: start;
justify-items: center;
}
.grid div {
background: lightskyblue;
padding: 20px;
text-align: center;
}
.grid div:nth-child(even) {
background: goldenrod;
}
</style>
</head>
<body>
<h2>Odkomentuj wybrane linie kodu CSS, aby zaobserwować różnice.</h2>
<pre>Grid 1</pre>
<div class="grid">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
<div class="four">4</div>
</div>
<pre>Grid 2</pre>
<div class="grid justify">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
<div class="four">4</div>
</div>
<pre>Grid 3</pre>
<div class="grid both">
<div class="one">1</div>
<div class="two">2</div>
<div class="three">3</div>
<div class="four">4</div>
</div>
</body>
</html>
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.