Created
November 7, 2019 11:00
-
-
Save bartwttewaall/9273c594ffd59ee22e2aa3e22008cc7b to your computer and use it in GitHub Desktop.
Calculate best fitting column size for dynamic list of content (bootstrap 12-columns layout)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set colClass = 'col-' ~ (12 / max(2, min(blogPosts.length, 4))) %} | |
<div class="row"> | |
{% for article in blogPosts %} | |
<article class="{{ colClass }}"> | |
... | |
</article> | |
{% endfor %} | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const calcColumnSize = (amount: number, min: number = 2, max: number = 4, total: number = 12) => { | |
return total / Math.max(min, Math.min(amount, max)); | |
} | |
const blogsColumnClass = "col-" + calcColumnSize(blogPosts.length); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment