0

First of all here's my code

I'm having a lot of difficulty centering the "container" div and its children. I've tried every type of positioning but i can't get it to stay centered after the browser is resized. I'm not sure where i'm going wrong and i've lurked the internet for hours to try and figure out why it's not positioning properly.

Any assistance is greatly appreciated

4

6 に答える 6

2
  • body要素を中央に配置しないでください。

  • 外側のdivを中央に配置します。中央に配置するには特定の幅が必要です。100%の中央に配置しても効果はありません。

  • jsfiddleに完全なWebページを貼り付けないでください。ページに折り返されるため、ページ要素が重複し、マークアップが無効になります。

http://jsfiddle.net/Guffa/2yree/14/

于 2012-08-21T10:07:06.863 に答える
1

実例:

http://jsfiddle.net/w4Wdy/

追加する必要があるのは次のとおりです。

#container{
    margin: auto;
    width: 620px;
}
于 2012-08-21T10:05:48.687 に答える
0

要素の#container幅は100%です。親と同じ幅の何かをどのように中央に配置できますか?できません。

要素が必要に応じて内側に収まるように幅を変更しますが、実際に中央に配置するために両側にスペースがあります。

#container {
    margin: 0 auto;
    width: 60%;
}

http://jsfiddle.net/Kyle_Sevenoaks/2yree/8/

于 2012-08-21T10:03:36.147 に答える
0

#container要素の幅を変更する必要があると思います。width:100%; 要素が中央に配置されないようにします。50%またはたとえばwidth:300pxに変更する必要があります。

于 2012-08-21T10:03:54.947 に答える
0

これをチェックしてくださいhttp://jsfiddle.net/2yree/11/

編集

http://jsfiddle.net/2yree/20/

于 2012-08-21T10:04:02.243 に答える
0

私はあなたがこのようなものを探していることを願っています

マークアップにいくつかのバグがあったので、いくつか変更を加えました。変更内容はこちらでご確認ください

于 2012-08-21T10:16:03.943 に答える