I have a parent div of the height 250px. Then I have a couple of children and set their min-height to 100%. I can tell from the debugger that the selector is correct and selects the correct elements, but the height doesn’t fill the height of the parent at all, and instead is the smallest as the content allows.
:root {
--poke-main: #e05e8e;
--poke-secondary: #f5ecc5;
--poke-tertiary: #b5255a;
}
.card {
border-color: var(--poke-tertiary);
}
.poke_tab {
border-radius: .25rem;
background-color: var(--poke-main);
color: var(--poke-secondary);
min-height: 100%;
}
#carousel {
min-height: 250px;
background-color: yellow;
}
.poke_container, .carousel-inner, .poke_tab, .poke_tab .card {
min-height: 100%; /* This doesn't work */
}
.poke_container .card {
background-color: var(--poke-secondary);
color: var(--poke-tertiary);
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<div id="carousel" class="col-lg-10" >
<!-- Infobox -->
<div class="poke_container">
<div class="carousel-inner">
<!-- Log Tab -->
<div class="poke_tab p-2">
<div class="card">
test
</div>
</div>
</div>
</div>
</div>
2
Answers
This is because parent elements don’t have a defined height.
When you set min-height: 100% on an element, it will only take up the available height if its parent has a specific height set.
In your case, the parent elements like
.poke_container
and.carousel-inner
don’t have a defined height, so themin-height: 100%
property doesn’t work as expected.The issue you’re facing with the child elements not filling the height of the parent is likely due to the use of
min-height: 100%
. When you usemin-height
, it will take the maximum of either the specified height or 100% of the parent’s height. If the content inside the child doesn’t require the full height, it won’t expand to fill it.To ensure that the child elements take up the full height of the parent, you can use the CSS flexbox or grid layout. Here’s an example of how you can modify your code using flexbox:
And in your HTML structure, you don’t need
min-height: 100%
for the child elements:With these modifications, the child elements will expand to fill the height of their parent while still accommodating the content’s height. Flexbox is a great way to handle such layouts where you want elements to take up available space dynamically.