0

I have a div at the bottom at a page. it's not bound by any other div. How would I manage to align it, a bit off center, with the main div. And place it at the top of the page, when the page has different heights and the div has to have a z-index:1; The two divs top has to be aligned, one cannot be higher than the other.

The html

<body>
    <div id="Main"><div> //Css or html for this div can not be edited
    <div id="Our_hero_div"><div> //This has to be show ontop of main, but a bit off-center
</body>

CSS

#Our_hero_div{
    z-index:1; //this much remain
}
#main {
    margin:auto;
}
4

1 回答 1

1

如果您无法获得 div 的#Our-hero-divINSIDE #main,并且无法编辑 div 的 CSS,那么#main您的选择将受到限制。#main您可以尝试给它一个绝对位置,并使用 csstop属性将其顶部与 div 的顶部对齐。

#Our-hero-div {
    position: absolute;
    top: 1em;   /* assumes the #main div has a margin top of 1em - just match this value to whatever the margin/padding of the #main div has on top */
}

您还需要使用leftright水平放置(对于您所追求的偏离中心的东西)。此解决方案仅在该#maindiv 确实位于主体顶部时才有效。如果有其他东西改变了上面的高度#main,那么这就会分崩离析。

于 2013-10-12T06:42:50.070 回答