css - 居中/底部堆叠的 div?

标签 css

我有一个像这样的 div 设置:

<div class ="outer">
    <div class = "inner"></div>
</div>

像这样使用 CSS:

.outer {
width: 300px;
height: 200px;
background: red;
}
.inner {
position: absolute;
width: 200px;
height: 50px;
background: black;
opacity: .5;
}

所以基本上是一个 div 堆叠在另一个 div 之上。但是,我希望顶部 div 位于父 div 的底部并居中,而不是左上角。我该怎么做?

最佳答案

听起来您希望内部 div 绝对定位在外部 div 中,在这种情况下,这应该可行:

.outer {
position: relative;
width: 300px;
height: 200px;
background: red;
}
.inner {
position: absolute;
width: 200px;
height: 50px;
bottom: 0px;
left: 50px;
background: black;
opacity: .5;
}

关于css - 居中/底部堆叠的 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14317072/

相关文章:

ASP.NET 3.5 - 在没有 "disabling"的情况下使字段只读/不可修改

html - 文本未与 Bootstrap 的导航栏文本右拉正确对齐

javascript - 制作android滑动结束效果

html - Bootstrap 将菜单折叠到垂直

html - 我想要没有容器流体的完整 div 但不改变容器宽度和结构?

html - 每页菜单相同

javascript - 试图让函数与 window.onload 循环但不起作用

jquery - ASP :panel hide and show and positioning

CSS - 打印 : repeat background through all the page

firefox - 我的 css 有问题,它在 mozilla firefox 上工作,但在 Chrome 和 safari 上不工作?