The best option to solve this problem is to use display: flex; with property align-items: stretch; . This is similar to @TrongLamPhan's answer, but he did not use align-items: stretch .
Edit: when enabling flexbox with display: flex; the default value for align-items will be stretch , so you do not need to add the align-items: stretch property, because it is the default value. Go vote, someone else will answer.
CSS breakdown:
- on
parent-div set display to flex . This will set the parent-div display mode to flexbox, which allows align-items property to be used. Set this property to stretch to match the child-div stretch.
CSS Tricks has a pretty good guide to flexbox . I would highly recommend flexbox training in 2017, because its a very powerful layout tool, and it should have been stable in all major browsers for a long time.
* { font-family: sans-serif; } .parent-div { margin: 0.5em; padding: 0.5em; background-color: #ddd; display: flex; align-items: stretch; } .child-div { flex: 1; margin: 0.5em; padding: 0.5em; background-color: #eee; }
<div class="parent-div"> <div class="child-div">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="child-div">This child div should be the same size!</div> </div>
Rico Kahler Apr 16 '17 at 8:00 2017-04-16 08:00
source share