我有div
(payslip-column-container
),其中包含三个子div(payslip-column
)元素
<div class="payslip-column-container">
<div class="payslip-column payments">
...
</div>
<div class="payslip-column deductions">
...
</div>
<div class="payslip-column payment-frequency">
...
</div>
</div>
.payslip-column-container {
height: 350px;
}
.payslip-column {
height: 100%;
}
我希望使三个子div元素成为容器高度的100%。如果我给payslip-column-container div一个特定的高度(350px)
,这可以正常工作如果我给容器div一个height: fit-content
然后它得到第一个子div的高度(这是最高的)但是其他两个div恢复到不尊重100%高度设置
我希望我的容器div成为最高子div的高度,然后其他两个div与最高的div相同
我能用这个标记实现这个目标吗?
答案 0 :(得分:1)
你可以通过flex实现这个目标
.payslip-column-container {
display: flex;
}
.payslip-column {
flex: 1 1 0;
border: 1px solid red;
max-width: 100%;
}
&#13;
<div class="payslip-column-container">
<div class="payslip-column payments">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
</div>
<div class="payslip-column deductions">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
</div>
<div class="payslip-column payment-frequency">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
</div>
&#13;