-3

重複の可能性:
divをdivの中央に配置する方法は?

幅と高さが100%の大きなDIVがあるので、ブラウザー全体を占有します。また、その中に幅1024px、高さ400pxの別のDIVがあります。divを水平方向と垂直方向の両方で中央に配置する最良の方法は何でしょうか?また、ブラウザのサイズが変更されたときに中央に配置したままにします。jQueryプラグイン、便利なjavascriptはありますか、それともCSSを使用してこれを行うことができますか?

マークアップ

.bigdiv{
height:100%;
width:100%;
background-color:#eee;
}
.smalldiv{
height:400px;
width:1024px;
background-color:#ccc;
}

<div class="bigdiv">
<div class="smalldiv"></div>
</div>

助けとアドバイスをありがとう!

4

4 に答える 4

0

使ってみてくださいmargin:0 auto;

.smalldiv{
height:400px;
width:1024px;
background-color:#ccc;
margin:0 auto;
}
于 2012-11-09T05:58:16.510 に答える
0

あなたは簡単margin:auto;にあなたの子供divをあなたの望む結果のために与えることができます

HTML

<div class="bigdiv">
<div class="smalldiv"></div>
</div>

CSS

 .bigdiv{
    height:100%;
    width:100%;
    background-color:#eee;
    }
    .smalldiv{
    height:400px;
    width:1024px;
    background-color:#ccc;
    margin:auto;
    }

デモ

于 2012-11-09T05:59:34.893 に答える
0

さて、これがそれを中心に置く方法です。

.bigdiv{
height:100%;
width:100%;
background-color:#eee;
position:relative;
}
.smalldiv{
height:400px;
width:1024px;
background-color:#ccc;
position:absolute;
left:50%;
top:50%;
margin-left:512px;
margin-top:200px;
}

<div class="bigdiv">
<div class="smalldiv"></div>
</div>
于 2012-11-09T06:20:44.663 に答える
-1

text-align:centerあなたのより大きなdivとmargin:0 auto あなたの内側のdivで使用する

于 2012-11-09T05:56:37.147 に答える