How come a percentage value for height
doesn’t work but a percentage value for width
does?
<div id="working"></div>
<div id="not-working"></div>
#working{
width:80%;
height:140px;
background:orange;
}
#not-working{
width:80%;
height:30%;
background:green;
}
The width of #working
ends up being 80% of the viewport, but the height of #not-working
ends up being 0.
另一种选择是向div添加样式
这意味着元素相对于最近定位的祖先进行了定位。