Skip to content

Instantly share code, notes, and snippets.

@colxi
Created August 15, 2019 11:45
Show Gist options
  • Save colxi/10d8fc2b9c9c2053c9d980fe04ebcc1b to your computer and use it in GitHub Desktop.
Save colxi/10d8fc2b9c9c2053c9d980fe04ebcc1b to your computer and use it in GitHub Desktop.
Adaptive grid layout (adjust min and max width, and elements per row)
<!-- behaviour example (gif) :https://cdn-images-1.medium.com/max/800/1%2A1FOrkyNbaabo3_LJxcdDbg.gif -->
<style>
.container {
display: grid;
grid-gap: 5px;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
grid-template-rows: repeat(2, 100px);
}
</style>
<div class="container">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment