I added a min-height
on a div
in a flex layout parent. It seems that the min-height
impacts the div
if its real height is greater than min-height
. Take below code as an example:
https://codepen.io/zhaoyi0113/pen/ejwJGM
I set 100px
as min-height on the div
but it gets overlay each other if its real height is greater than 100. In above case, I expect the div
shows hello
world
in one block but it doesn't. If you inspect the dom structure you will find that the <p>
doesn't extend its parent div
height. How can I fix it?
Since you've set height 200px on the .div1
flex box tries to fit all the child elements inside 200px, but the min-height prevents it to fit all children within the 200px.
Depending on what you want to achieve you might want to change the height on the .div1
or add flex-shrink: 0
on .div2
try changing the height of the paragraph to inherit.
p {
height: inherit;
}
this will make it inherit the height from its parent.
Alternative solution is to add display: table;
to your div2.
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.