Skip to content

Instantly share code, notes, and snippets.

@BaseCase
Created September 26, 2021 18:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaseCase/c95f202834f7300b551487c6ba6d3a39 to your computer and use it in GitHub Desktop.
Save BaseCase/c95f202834f7300b551487c6ba6d3a39 to your computer and use it in GitHub Desktop.
basic centered grid
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Layout demo</title>
<style>
* {
box-sizing: border-box;
}
html, body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
}
.container {
width: 100%;
height: 100%;
display: grid;
grid-template-columns: 150px 150px 150px;
grid-template-rows: 150px 150px 150px;
column-gap: 15px;
row-gap: 10px;
place-content: center;
}
.cell {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.cell .img-container {
width: 100%;
overflow: hidden;
}
.cell .img-container img {
width: 100%;
object-fit: cover;
}
.cell.two-wide {
grid-column: span 2;
}
.cell.two-tall {
grid-row: span 2;
}
.cell p {
font-family: sans-serif;
font-size: 12pt;
text-align: center;
margin: 0;
padding: 0.5em 0 0 0;
}
</style>
</head>
<body>
<div class="container">
<div class="two-wide cell">
<div class="img-container">
<img alt="" src="https://www.fillmurray.com/300/200"/>
</div>
<p>hello world</p>
</div>
<div class="cell">
<div class="img-container">
<img alt="" src="https://www.fillmurray.com/200/200"/>
</div>
<p>forward</p>
</div>
<div class="two-tall cell">
<div class="img-container">
<img alt="" src="https://www.fillmurray.com/300/600"/>
</div>
<p>ping</p>
</div>
<div class="cell">
<div class="img-container">
<img alt="" src="https://www.fillmurray.com/200/200"/>
</div>
<p>refs</p>
</div>
<div class="cell">
<div class="img-container">
<img alt="" src="https://www.fillmurray.com/200/200"/>
</div>
<p>data</p>
</div>
<div class="cell">
<div class="img-container">
<img alt="" src="https://www.fillmurray.com/200/200"/>
</div>
<p>git</p>
</div>
<div class="cell">
<div class="img-container">
<img alt="" src="https://www.fillmurray.com/200/200"/>
</div>
<p>amp</p>
</div>
</div>
</body>
</html>
@BaseCase
Copy link
Author

Rendered, this gets you a page that looks like this:

example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment