2014-03-28 61 views
0

我已經使用了搜索功能,它不會center,因爲我無法理解一些建議,而那些我無法工作。谷歌也沒有給我任何結果。不能將div放在另一個div內

我想用1個div作爲'背景',這樣屏幕下的第一個150px就是藍色的。

然後我想要centered框中的徽標950px寬由150px下來。

「logo div」(我稱之爲headercontent)需要位於headerbackgroundblue div的頂部,這是我管理的。

但是它不會居中該專區內(950px寬心將存儲的所有內容,以便它看起來在所有屏幕好箱子,但藍色是1920px寬,使網站更好看在更大的分辨率。

CSS

body { 
    padding: 0; 
    margin: 0; 
} 
.headercontent { 
    z-index: 2; 
    position: absolute; 
    height: 150px; 
    width: 950px; 
    margin-right: auto; 
    margin-left: auto; 
} 
.bluebackgroundtop { 
    height: 150px; 
    width: 1920px; 
    margin-right: auto; 
    margin-left: auto; 
    background-color: #3c56a6; 
    z-index: 1; 
    position: absolute; 
} 

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <title>Kleenzone - Commercial Cleaning Services</title> 
     <link href="style/style.css" rel="stylesheet" type="text/css" /> 
    </head> 

    <body> 
     <div class="bluebackgroundtop"></div> 
     <div class="headercontent"> 
      <H1> KLEENZONE </H1> 
     </div> 
    </body> 
</html> 
+2

請提供的HTML代碼,太。 – KittMedia

+0

提供HTML代碼。 – SN1Dan

+0

normaly你會做這樣的事情:http://jsfiddle.net/NicoO/42A8M/ –

回答

2

你需要有.headerContent.bluebackgroundtop div中,然後風格是這樣的:

* { 
    padding: 0; 
    margin: 0; 
} 
.headercontent { 
    height: 150px; 
    width: 950px; 
    margin:0 auto; 
    text-align:center; 
} 
.bluebackgroundtop { 
    height: 150px; 
    width: 1920px; 
    margin:0 auto; 
    background-color: #3c56a6; 
} 

DEMO

+0

這幾乎可以奏效,但現在白色? – SN1Dan

+0

這是因爲'用戶代理樣式表' - 它應用自動邊距和填充。我使用通用選擇器將其清除,但在現實生活中,您應該使用[reset.css](http://www.cssreset.com/)。 http://jsfiddle.net/GaurangTandon/syZdH/2/ –

+0

@ user3086732這是否符合要求? –