There's column-count
, but I'm wondering is there such thing as "item-count" for items inside a CSS column? I'm having trouble trying to keep the number of items fixed in my 3 Column FAQs without specifying height to the column itself.
In this example, I would like for each column to have 3 items, no matter how long the question or answer in each item is. In the actual site, I won't know the exact number of items so I'd just like to keep them "balanced".
You can see that I tried using flexbox but the answer panel will hold dynamic content (same goes with the number of questions/items). My aim is to make it look like a masonry-layout whenever the answer panel(s) is/are displayed.
.m-faqs {
/*display: flex;
flex-flow: row wrap;
justify-content: space-between;*/
column-count: 3;
column-gap: 50px;
}
.m-faqs_item {
margin-bottom: 20px;
position: relative;
/*flex: 0 0 47%;
align-self: baseline;*/
display: inline-block;
break-inside: avoid;
width: 100%;
}
.m-faqs_title {
margin-top: 0;
margin-bottom: 0;
}
.m-faqs_question {}
.m-faqs_question-link {
display: inline-block;
}
.m-faqs_answer {}
.m-faqs_item.active .m-faqs_answer {
display: block;
}
<div class="m-faqs">
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Here's the answer.</p>
</div>
</div>
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Here's the answer.</p>
</div>
</div>
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Here's the answer.</p>
</div>
</div>
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Here's the answer.</p>
</div>
</div>
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Here's the answer.</p>
</div>
</div>
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Here's the answer.</p>
</div>
</div>
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Here's the answer.</p>
</div>
</div>
<div class="m-faqs_item">
<h3 class="m-faqs_title"><span class="m-faqs_question">Question here</span></h3>
<div class="m-faqs_answer">
<p>Here's the answer.</p>
</div>
</div>
</div>