Css 设置子元素';s高度或父元素';她身高多少?

Css 设置子元素';s高度或父元素';她身高多少?,css,Css,设置父元素的高度并基于父元素调整所有子元素的高度是否是最佳做法?比如说 #parent { width: 100%; height: 50px; } .childOne { height: 50%; } .childTwo { height: 100%; } #parent { width: 100%; } .childOne { width: 100%; height: 100px; } .childTwo { width: 1

设置父元素的高度并基于父元素调整所有子元素的高度是否是最佳做法?比如说

#parent {
    width: 100%;
    height: 50px;
}
.childOne {
    height: 50%;
}
.childTwo {
    height: 100%;
}
#parent {
    width: 100%;
}
.childOne {
    width: 100%;
    height: 100px;
}
.childTwo {
    width: 100px;
    height: 50px;
}
或者,由于父图元会自动调整为与最大的子图元相同的高度,因此最佳做法是设置子图元的大小并允许父图元进行相应的调整吗?比如说

#parent {
    width: 100%;
    height: 50px;
}
.childOne {
    height: 50%;
}
.childTwo {
    height: 100%;
}
#parent {
    width: 100%;
}
.childOne {
    width: 100%;
    height: 100px;
}
.childTwo {
    width: 100px;
    height: 50px;
}

这取决于具体情况。你能详细说明一下吗?这取决于你是希望父母的身高是动态的,还是希望孩子的身高是动态的。对于静态站点,您可以选择其中一个。@4castle说我希望两者都是动态的。我不确定我是否理解这意味着什么。您希望孩子的孩子来确定身高吗?