11

我正在一个使用位置的网站上工作:包含位置的相对 div:绝对 div。我理解我相信的概念,一切都很好,除了我似乎无法获得top做任何事情的属性。左作品,但不是顶部。我的代码如下:

<div id="imagemenu">
    <div class="west">
        <img src="/makingmusicstore/wp-content/themes/makingmusic/img/west.png" alt="west">
    </div>
    <div class="southwest">
        <img src="/makingmusicstore/wp-content/themes/makingmusic/img/southwest.png alt=" southwest ">
    </div>
    <div class="south ">
        <img src="/makingmusicstore/wp-content/themes/makingmusic/img/south.png " alt="south ">
    </div>
    <div class="logo ">
        <img src="/makingmusicstore/wp-content/themes/makingmusic/img/logo.png " alt="Making Music Store ">
    </div>
</div>

CSS

#imagemenu {
    position: relative;
}
.logo img {
    position: absolute;
    width: 20%;
    top: 50%;
    left: 40%;
}
.west img {
    position: absolute;
    width: 30%;
    left: 15%;
}
.southwest img {
    position: absolute;
    width: 30%;
    left: 15%;
}
.south img {
    position: absolute;
    left: 35%;
}

该网站是 adams-web.net/makingmusicstore,目前一团糟,直到我可以让 top 属性正常工作。在我看来,徽标应该位于页面下方,但它并没有像我认为的那样工作。我不确定我错过了什么。当我将位置更改为静态时它确实有效,但它不能正确保持位置。

4

2 回答 2

22

Hey now define your parent div height than used top % in top absolute div

Like this:

.parent {
    position: relative;
    height: 100px;
}
.child {
    position: absolute;
    top: 50%;
}

If you don't define your parent div height than used to px value in top

.child {
    top: 100px;
}
于 2012-08-13T04:54:54.250 回答
6

Add width and height to #imagemenu

For example:

#imagemenu {
    width: 100%;
    height: 400px;
}

Then check again if position: absolute is working or not.

于 2012-08-13T04:55:50.420 回答