html - 如何通过 CSS 对齐父级 "relative"之外高度未知的绝对 DIV?

标签 html css position css-position

考虑一个简单的 example用 html

<div class="parent">
    <div class="child">
    </div>
</div> 

和CSS

.parent{
    position:relative;
    background:red;
    width:200px;
    height:40px;
}
.child{
    position:absolute;
    top:40px;
    left:30px;
    width:70px;
    height:70px;
    background:blue;
}

将绝对位置的 DIV 放置在其父级(具有相对位置)的正下方。 enter image description here

在这个例子中,我将绝对值的顶部等于父级相对值的高度。

高度未知(父子)时,如何在父级下方对齐绝对DIV?

最佳答案

没想到this我自己会工作,但它似乎:

html, body {
    height: 100%;
}
.parent{
    position:relative;
    background:red;
    width:200px;
    height:40px;
}
.child{
    position:absolute;
    top:100%;
    left:30px;
    width:70px;
    height:70px;
    background:blue;
}

关于html - 如何通过 CSS 对齐父级 "relative"之外高度未知的绝对 DIV?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14773983/

相关文章:

c# - 获取正在运行的应用程序的屏幕

html - 选择在 CSS 中具有相同类的另一个元素之前的元素

html - 页面高度不适应页面新内容

JavaFX - 仅显示一个标签

android - 其他按钮下方的按钮以编程方式android

在 iPad 上具有绝对位置的 CSS 中心元素

html - 对表行中的所有元素应用缩放变换

javascript - 使用 jQuery 从下拉列表中提取信息并使用该信息创建一个 div

jquery 数据表修复了在 IE 中不对齐的列

jQuery:获取扩展特定类的CSS类的元素