我的DIV位于之前的DIV之上

时间:2014-06-06 20:21:54

标签: html css

我刚刚开始把我的网站放在一起。我有一个滚动的横幅DIV,现在我想在“bigmenubutton'下面添加一个图像。 DIV但是当我把它放在我的横幅上面时?我已经放入CSS来清除:但是这不起作用。

HTML

       <body>
        <div class="mainhome">
            <div class="header">
              <div class="menubutton-leftside" style="margin-right:23px"><h2>home</h2></div>
              <div class="menubutton-leftside" style="margin-right:20px"><h2>about</h2></div>
              <div class="menubutton-leftside" style="margin-right:30px"><h2>portfolio</h2></div>
              <div class="menubutton-leftside" style="margin-right:27px"><h2>contact</h2></div>
                <div class="logo"><img src="images/es-logo.png" width="170" height="170" /></div> 
              <div class="menubutton-rightside" style="margin-left:17px"><h2>print</h2></div>
              <div class="menubutton-rightside" style="margin-left:25px"><h2>digital</h2></div>
              <div class="menubutton-rightside" style="margin-left:38px"><h2>illustration</h2></div>
              <div class="menubutton-rightside" style="margin-left:20px"><h2>brand</h2></div>
          </div>
                <div class="mainimage">
                <div id="slider_container">
          <div id="slides">
                        <img src="images/slider/emmasteed.png" alt="Emma Steed Graphic Art and Web Design" />
                        <img src="images/slider/graphicdesign-desk.png" alt="Emma Steed Graphic Art and Web Design" />
          </div>
        </div>
    <div class="bluebar"></div></div>
                <div class="largemenubutton"><img src="images/portfolio.png" /></div>
        </div>

CSS

@charset "UTF-8";
/* CSS Document */

body {
    background-image:url(images/header-background.png);
    background-repeat:repeat-x;
    margin:0;
}

.mainhome {
    width: 855px;
    margin-top: 0;
    margin-right: auto;
    margin-bottom: 0;
    margin-left: auto;
}

.header {
    height: 236px;
    background-image:url(images/header-background.png);
    background-repeat:repeat-x;
    clear:left;
}

.mainimage {
    width: 855px;
    height: 423px;
    background-color:#0C9;
    position:absolute;
    top:220px;
    clear:left;
    float:left;
    z-index:-1;
}

#slider_container {
        width:855px;
        height:423px;
        overflow:hidden;
}

.bluebar {
    width: 855px;
    height: 16px;
    background-color:#334d5c;
    clear:left;
    float:left;
}

.menubutton-leftside {
    width:60px;
    height:20px;
    float:left;
    margin-top:95px;
}

.menubutton-rightside {
    width:60px;
    height:20px;
    float:left;
    margin-top:95px;
    text-align:right;
}

h2 {
    font-family:Tahoma, Geneva, sans-serif;
    font-size:12px;
    font-weight:normal;
    color:#666;
    display:inline;
}

.logo {
    width:170px;
    height:170px;
    float:left;
    margin-top:30px;
}

.largemenubutton {
    width:261px;
    height:259px;
    float:left;
    clear:left;
}

JSFIDDLE在这里 http://jsfiddle.net/cX8Z9/

1 个答案:

答案 0 :(得分:0)

问题是在</div>之后还有一个额外的bluebar,因此largemenubutton不在同一个容器mainimage内,该容器位于绝对位置(所以如果largemenubutton根本不在那里,mainimage就坐在原处。{/ p>

<div class="bluebar"></div></div>
<div class="largemenubutton"><img src="images/portfolio.png" /></div>

你无法清除&#34;绝对定位你可以浮动的方式。
因此,解决方案是将有问题的</div>两行向下移动,从而将largemenubutton放在mainmenu内。

<div class="bluebar"></div>
<div class="largemenubutton"><img src="images/portfolio.png" /></div>
</div>

请参阅jsFiddle