正如标题所说,当在父div上启用flex-Wrap:WRAP时,子网格容器的高度会加倍.我希望它不要这么做,但更重要的是,为什么会发生这种情况?
我以为如果/当添加更多网格项以使其换行时,网格的高度会简单地进行调整……但我显然遗漏了一些东西.
我希望它看起来像启用flex-wrap:nowrap
时的样子,但我也希望它能包装起来……
.container {
width: 88%;
margin: 2rem auto;
max-width: 1400px;
}
.cno-event-search-filters__container {
display: flex;
flex-direction: column;
align-items: stretch;
}
.cno-event-search-filters__filter-container {
border: 2px solid black;
display: grid;
grid-template-columns: repeat(auto-fit, max(240px));
gap: 1rem;
}
<div class="container">
<div class="cno-event-search-filters">
<div class="cno-event-search-filters__container">
<h4 class="cno-event-search-filters__title">Event Types</h4>
<div class="cno-event-search-filters__filter-container">
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Culture">
<label for="Culture">Culture</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Entertainment">
<label for="Entertainment">Entertainment</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Sports">
<label for="Sports">Sports</label>
</div>
</div>
</div>
<div class="cno-event-search-filters__container">
<h4 class="cno-event-search-filters__title">Locations</h4>
<div class="cno-event-search-filters__filter-container">
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Ampitheatre">
<label for="Ampitheatre">Ampitheatre</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Capitol Lawn">
<label for="Capitol Lawn">Capitol Lawn</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Capitol Museum">
<label for="Capitol Museum">Capitol Museum</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Chapel">
<label for="Chapel">Chapel</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Choctaw Village">
<label for="Choctaw Village">Choctaw Village</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Playground">
<label for="Playground">Playground</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Red Warrior Park">
<label for="Red Warrior Park">Red Warrior Park</label>
</div>
<div class="cno-event-search-filters__filter">
<input type="checkbox" id="Stickball Field">
<label for="Stickball Field">Stickball Field</label>
</div>
</div>
</div>
</div>
</div>