Svelte Grid Snippet
I often find myself looking for this particular piece of code. This is just a simlpe responsive CSS grid that takes two parameters: col
(default: 20rem) and gap
(default: 0rem). This tiny snippet will create a fully responsive grid component. Try it yourself.
<script>
// Grid.svelte
export let col = 20
export let gap = 0
</script>
<div class={$$props.class} style="--col: {col}rem; --gap: {gap}rem;">
<slot />
</div>
<style>
div {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(var(--col), 100%), 1fr));
gap: var(--gap);
}
</style>
The example above is Svelte code but it is simple enough you can easily translate it to either framework of your choice or just plain old html and css.
- Blank Bookmarks Slate Sep 24, 2024
- JavaScript Search Query Snippet May 30, 2024
- Vercel Open Graph Card With No Framework Mar 13, 2024
- Svelte Grid Snippet Mar 02, 2024
- Hello World Mar 01, 2024