2013-01-22 74 views
0

對不起,如果這是之前問過,但我閱讀並沒有看到我的錯誤。我嘗試以#邊界爲中心#邊界:0自動;但沒有任何反應......寬度也被設置。CSS居中邊距:0 auto;問題

這是CSS: 我想洞頁被centerd

@charset "utf-8"; 
body { 
    margin-left:0px; 
    margin-top:0px; 
    margin-right:0px; 
    margin-bottom:0px; 
    padding:0; 
    background-color:#000000; 
    text-align:center 

} 
#wrapper { 
    width: 901px; 
    ***margin: 0 auto;*** 
} 
#header { 
    background-image: url(images/banner.jpg); 
    background-repeat: no-repeat; 
    float: left; 
    height: 233px; 
    width: 901px; 
} 
#menu { 
    font-family: Arial, Helvetica, sans-serif; 
    background-image: url(images/menu.gif); 
    background-repeat: no-repeat; 
    text-align: center; 
    word-spacing: 70px; 
    padding-top: 17px; 
    float: left; 
    height: 33px; 
    width: 901px; 
} 
#main { 
    float:left; 
    height:auto; 
    width:901px; 
} 
#leftcol { 
    float:left; 
    height:auto; 
    width:300px; 
    padding-top:5px; 
    padding-right:0px; 
    padding-bottom:0px; 
    padding-left:30px; 
} 
#rightcol { 
    float:right; 
    height:auto; 
    width:500px; 
    padding-right:35px; 
    margin-right:0px; 
} 
#footer { 
    font-family:Arial, Helvetica, sans-serif; 
    font-size:x-small; 
    float:left; 
    height:250px; 
    width:900px; 
    color:#666666; 
    clear:both 
} 

而且在html:

這是基本的HTML文件

<!DOCTYPE html> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<link href="style.css" rel="stylesheet" type="text/css" /> 

</head> 

<body> 
<div id="wrapper">Content for id "wrapper" Goes Here</div> 
<div id="header">Content for id "header" Goes Here</div> 
<div id="menu">Content for id "menu" Goes Here</div> 
<div id="main"> 
    <div id="leftcol">Content for id "main" Goes Here</div> 
    <div id="rightcol">Content for id "rightcol" Goes Here</div> 
    <div id="footer">Content for id "footer" Goes Here</div> 
</div> 
</body> 
</html> 

回答

0

你需要給身體(你的元素的父母)的寬度:

html, body{ 
    width:100%; 
} 

此外,考慮你的標記,如果你想爲中心的整個網站,你應該用你的#wrapper作爲一個實際的包裝,這意味着它應該包括其他內容節點:

<body> 
<div id="wrapper"> 
    <div id="header">Content for id "header" Goes Here</div> 
    <div id="menu">Content for id "menu" Goes Here</div> 
    <div id="main"> 
     <div id="leftcol">Content for id "leftcol" Goes Here</div> 
     <div id="rightcol">Content for id "rightcol" Goes Here</div> 
     <div id="footer">Content for id "footer" Goes Here</div> 
    </div> 
</div> 
</body> 
+0

啊,但仍然不整個事情的中心... –

+0

增加寬度:100%;身體(#包裝的父母)仍然是相同的。我也知道IE瀏覽器,但這發生在Chrome和Firefox。 –

+0

編輯我的帖子,看看如何解決你的標記。 – darma