2014-06-06 20 views
-1

我剛開始把我的網站放在一起。我有一個滾動橫幅DIV,現在我想在'largemenubutton'DIV下添加一個圖像,但是當我將它放在我的橫幅上時?我已經把CSS清除了:但是這不起作用。我的DIV位於以前的DIV之上

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/

+2

您好,如果您使用jsfiddle添加了一個示例,我們可以使用它來查看並嘗試修復您的問題,這將有所幫助! http://jsfiddle.net/ – JustcallmeDrago

回答

0

的問題是,存在bluebar後,一個額外的</div>,所以日e largemenubutton不在同一個容器mainimage內,該容器絕對定位(因此,如果mainimage根本不在那裏,那麼largemenubutton就坐在它將坐的位置)。

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

而且你不能「清除」絕對定位你可以浮動的方式。
因此,解決方案是將違規的</div>兩行下移,從而將largemenubutton置於mainmenu之內。

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

請參閱jsFiddle

+0

謝謝!這工作完美! – user3714234