div.container {
display: flex;
flex-direction: column;
height: 100%;
}
div.container div.block {
display: flex;
justify-content: center;
align-items: center;
}
div.container div.advanced-items {
display: flex;
flex-direction: column;
overflow-y: scroll;
height: 100%;
}
div.container div.advanced-items span {
height: 100px;
}
<div class="container">
<div class="block">
<span>some data here</span>
</div>
<div class="block">
<span>some data here</span>
</div>
<div class="advanced-items">
<span>1. item</span>
<span>2. item</span>
<span>3. item</span>
<!-- more items here -->
</div>
</div>
div.advanced-items
高度值被设置为100%
,但它在某种程度上等于整个div.container
高度。但考虑到孩子的身高,我需要填写div.container
的剩余身高。
请帮帮我,怎么做?
考虑到孩子的身高,我需要填充div.container
的剩余高度确切地说,看看它是如何发生的,只需将border
添加到div.advanced-items
中,看看它包裹的空间有多大
div.container {
display: flex;
flex-direction: column;
height: 100%;
border: 1px solid black;
}
div.container div.block {
display: flex;
justify-content: center;
align-items: center;
}
div.container div.advanced-items {
display: flex;
flex-direction: column;
overflow-y: scroll;
height: 100%;
border: 1px solid black;
}
div.container div.advanced-items span {
height: 100px;
}
<div class="container">
<div class="block">
<span>some data here</span>
</div>
<div class="block">
<span>some data here</span>
</div>
<div class="advanced-items">
<span>1. item</span>
<span>2. item</span>
<span>3. item</span>
<!-- more items here -->
</div>
</div>
现在,div.advanced-items
正在包装除上面的divs
包装的高度之外的所有左侧高度,但您可以通过将它们的height
设置为100%
来使它们平均共享其父级的高度
div.container {
display: flex;
flex-direction: column;
height: 100%;
border: 1px solid black;
}
div.container div.block {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
border: 1px solid black;
}
div.container div.advanced-items {
display: flex;
flex-direction: column;
overflow-y: scroll;
height: 100%;
border: 1px solid black;
}
div.container div.advanced-items span {
height: 100px;
}
<div class="container">
<div class="block">
<span>some data here</span>
</div>
<div class="block">
<span>some data here</span>
</div>
<div class="advanced-items">
<span>1. item</span>
<span>2. item</span>
<span>3. item</span>
<!-- more items here -->
</div>
</div>
你想要这样吗?:
div.container {
display: flex;
flex-direction: column;
height: 100%;
}
div.container div.block {
display: flex;
justify-content: center;
align-items: center;
}
div.container div.advanced-items {
display: flex;
flex-direction: column;
overflow-y: scroll;
height: 100%;
}
div.container div.advanced-items span {
height: calc(100% / var(--item-count));
min-height : 100px;
}
<div class="container">
<div class="block">
<span>some data here</span>
</div>
<div class="block">
<span>some data here</span>
</div>
<div style="--item-count:3;" class="advanced-items">
<span>1. item</span>
<span>2. item</span>
<span>3. item</span>
<!-- more items here -->
</div>
</div>
或者这个?:
div.container {
display: flex;
flex-direction: column;
height: 100%;
}
div.container div.block {
display: flex;
justify-content: center;
align-items: center;
}
div.container div.advanced-items {
display: flex;
flex-direction: column;
justify-content: stretch;
overflow-y: scroll;
height: 100%;
}
div.container div.advanced-items span {
height: 100px;
}
<div class="container">
<div class="block">
<span>some data here</span>
</div>
<div class="block">
<span>some data here</span>
</div>
<div style = "--itemCount:3;" class="advanced-items">
<span>1. item</span>
<span>2. item</span>
<span >3. item</span>
<!-- more items here -->
</div>
</div>