有column-count
,但我想知道 CSS 列中的项目是否有“项目计数”之类的东西?我在尝试在我的 3 Column FAQs 中保持固定的项目数量而不指定列本身的高度时遇到了麻烦。
在此示例中,我希望每列有 3 个项目,无论每个项目中的问题或答案有多长。在实际站点中,我不知道项目的确切数量,所以我只想让它们保持“平衡”。
您可以看到我尝试使用 flexbox,但答案面板将包含动态内容(问题/项目的数量也是如此)。我的目标是在显示答案面板时让它看起来像砖石布局。
.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>