相关疑难解决方法(0)

相对父母,绝对按百分比垂直定位?

我正在尝试按百分比创建垂直定位的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%的垂直位置.我错过了什么?提前致谢!

css position

20
推荐指数
2
解决办法
3万
查看次数

标签 统计

css ×1

position ×1