Skip to content

Instantly share code, notes, and snippets.

@stychos
Last active January 16, 2024 17:51
Show Gist options
  • Save stychos/37ec7e4253a5563e5595144c15f47751 to your computer and use it in GitHub Desktop.
Save stychos/37ec7e4253a5563e5595144c15f47751 to your computer and use it in GitHub Desktop.
Simplified pure CSS (almost) drop-in Bootstrap Grid replacement
:root {
--rows-column-count: 4;
--rows-column-gap: 1em;
}
.row {
display: flex;
box-sizing: border-box;
flex-flow: row wrap;
justify-content: flex-start;
align-items: stretch;
gap: var(--rows-column-gap);
margin-bottom: var(--rows-column-gap);
}
.row > .col {
--col-width: calc(100% / var(--rows-columns-count) - (var(--rows-column-gap) - var(--rows-column-gap) / var(--rows-columns-count)));
flex-basis: var(--col-width);
box-sizing: border-box;
}
.row > .col-2 {
flex-basis: calc(var(--col-width) * 2 + var(--rows-column-gap));
}
.row > .col-3 {
flex-basis: calc(var(--col-width) * 3 + var(--rows-column-gap) * 2);
}
.row > .col-4 {
flex-basis: calc(var(--col-width) * 4 + var(--rows-column-gap) * 4);
}
@media only screen and (max-width: 768px) {
.row {
display: block;
}
.row > .col {
margin-bottom: var(--rows-column-gap);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment