-7
#container {
width: 960px;
margin-left: auto;
margin-right: auto;
height: auto; }

#large_box {
text-align: center;
width: 960px;
margin-left: auto;
margin-right: auto;
height: auto; }

#searchbcid {
position: absolute;
left: 400px;
margin-left: 50px;
top: 280px; }

#createbcid {
position: absolute;
margin-left: 250px;
top: 280px;
left: 550px; }

#loginpos {
position: absolute;
margin-left: 20px;
left: 30px;
top: 280px; }

私のhtmlには、という名前のdivがありcontainerます。他divのすべての はコンテナ内に配置されます。、、などのlarge_box3 つの他の を含む別の div ie 。divloginpossearchbcidcreatebcid

しかし、私は中央揃えにすることはできませんdiv large_box

どうすれば中央揃えにできますか?

4

5 に答える 5

0

cssでは margin:0 auto; 、divにある程度の幅を使用するだけで、指定された幅の中央に自動的に配置されます。

ハッピーコーディング...

于 2013-03-12T10:19:25.667 に答える
0

これは私にとってはうまくいきます。

CSS

div#center{
      width:250px;
      margin:0 auto;
      background-color:yellow;
}

/* To support IE */
div#parent{
      align:center;
}

HTML

    <div id="parent">    
      <div id="center">
        I'm in the middle!
      </div>
    </div>

JSFiddle リンク

于 2013-06-22T19:21:40.503 に答える
0

マージンを 0 auto に設定してみてください。指定した幅でコンテナ内の要素を水平方向に中央揃えにします。

#large_box {
text-align: center;
width: 960px;
margin: 0 auto;
height: auto; }
于 2014-08-10T22:52:57.463 に答える
0

CSS:

#wrapper_div{
width:500px;
height:500px;
}

#inner_div{
width:200px;
margin:0 auto;
}

HTML:

<div id="wrapper_div">
<div id="inner_div">
Centred content here!
</div>
</div
于 2013-05-29T15:21:05.737 に答える