0

HTML/CSS の経験はあまりありませんが、ページ コンテナーとして機能する中央の div がある単純なレイアウトを実現しようとしています。他の例を調べてみましたが、なぜ私のものが機能しないのかわかりません (ヘッダーは表示されますが、左揃えになっています。中央に配置したいのです):

html:

<!DOCTYPE html>
<html>
<head>
  <title>title</title>
  <script type="text/javascript" src="script.js"></script>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <div id="container">
    <div id="header"></div>
  </div>
</body>
</html>

CSS:

body {
    background: #fff;
    font-family: Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    text-align: center;
}

#container {
    background: #bbb;
    width: 800px;
    margin: 0, auto;
}

#header, #footer {
    background: #333;
    height: 40px;
}
4

4 に答える 4

2
margin: 0, auto;

する必要があります

margin: 0 auto;
于 2013-01-30T10:58:20.737 に答える
0

のカンマを削除margin:

margin: 0 auto;

それ以外の

margin: 0, auto;
于 2013-01-30T10:59:06.387 に答える
0

の間に , がmargin:0あり、auto;これは無効なCSS 用語です

margin: 0, auto;

する必要があります

margin: 0 auto;
于 2013-01-30T10:59:14.500 に答える
0

このデモをチェック

body {
    background: #fff;
    font-family: Helvetica, Arial, sans-serif;
    width: 100%; /* You need to mention the width here (Good way)*/
    padding: 0;
    text-align: center;
}

#container {
    background: #bbb;
    width: 800px;
    margin: 0 auto;  /* You are doing wrong here (margin: 0, auto;) */
}

#header, #footer {
    background: #333;
    height: 40px;
}

margin: 0 auto;(無効) の代わりに (有効margin: 0, auto;)

于 2013-01-30T11:04:49.817 に答える