我正在尝试按百分比创建垂直定位的DIV.我有父容器设置为相对,内容div设置为绝对.当我使用像素定位内容div时,这可以正常工作,但是当我尝试百分比时,百分比被忽略:
.container {
position: relative;
}
.content {
position: absolute;
left: 10%;
top: 50%;
}
<div class="container"><div class="content"> This is the content div. It should be 10% from the left of the container div.
</div></div>
Run Code Online (Sandbox Code Playgroud)
内容div显示在页面顶部,忽略50%的垂直位置.我错过了什么?提前致谢!