简体   繁体   中英

Give all div elements within a div 100% height if container has flexible height

I have a div ( payslip-column-container ) that contains three child div ( payslip-column ) elements

<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%;
}

I wish to make the three child div elements be 100% the height of the container. This works fine above if I give the payslip-column-container div a specific height (350px)

If I give the container div a height: fit-content then it gets the height of the first child div (which is the tallest) but the othertwo divs revert back to not respecting the 100% height setting

I want my container div to be the height of the tallest child div and then the other two divs to be the same height as the tallest

Can I achieve this with this markup?

you can achieve this by flex

 .payslip-column-container { display: flex; } .payslip-column { flex: 1 1 0; border: 1px solid red; max-width: 100%; } 
 <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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM