<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;
}
.grid div {
background: lightskyblue;
padding: 20px;
text-align: center;
}
.grid div:nth-child(even) {
background: goldenrod;
}
/* Style CSS nakładane bezpośrednio na elementy siatki. */
.one {
/* Lewy górny róg, czyli pozycja na samej górze i po lewej stronie.*/
align-self: start;
justify-self: start;
}
.two {
align-self: center;
justify-self: center;
}
.four {
align-self: end;
justify-self: end;
}
</style>
</head>
<body>
<pre>Samopozycjonowanie</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>
</body>
</html>
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.