# 定位且限制最大高度
在实际应用中,使用定位且加上最大高度限制,使用了fixed定位,且left,right,bottom,top均设为0,但是最大高度被默认为高度了。
经过调试,使用top:50%;left:50%;transform:translate(-50%,-50%)配合最大高度可以实现想要的效果,即在高度没达到最大高度前高度靠内容撑开,达到最大高度后就不再继续改变height。
#qunpeople
position fixed
top 50%
left 50%
transform: translate(-50%,-50%);
background #e8e8e8
margin auto
width 400px
max-height 400px
overflow-y auto
# margin-top 与百分比
pc端测试:使用margin-top:50%; 结果margin-top是根据当前 父级元素的width 的50%来设置上外边距!