あなたが本当に親div
は(あなたが達成しようとしているものに基づいて、どのような理由のために)その子要素の周りに崩壊する場合、あなたはその後div
こと、そしてベクターの@中心にしたいです答えは上にあり、display: table
とmargin: 0 auto
を使用してください。
div
は、子供をセンターに入れようとしているコンテナの全幅まで拡大しても問題ない場合は、状況に応じて少なくとも2つ以上のオプションがあります。
text-align: center
を使用できます。
.content {
text-align: center;
border-style: solid;
border-width: thin;
}
.content span {
display: inline;
border-style: solid;
border-width: thin;
}
<div class="content">
<div>Test</div>
<div>Test</div>
</div>
はまた、あなたはもちろん、サポートしているブラウザの互換性のレベルに応じて、justify-content: center
とdisplay: flex
以降を使用することができます。
.content {
display: flex;
justify-content: center;
border-style: solid;
border-width: thin;
}
.content div {
border-style: solid;
border-width: thin;
}
<div class="content">
<div>Test</div>
<div>Test</div>
</div>
いくつかの可能性があります: '表示:インラインblock'が、このために良いですが、([IE7ハック](http://stackoverflow.com/a/6545033/870729を意識します)) –
'display:inline-block'を親に設定し、コンテナで囲みます' text-align:center; ' –
これは小さな問題のように見えますので、HTMLを表示すると、あなたが直面している挑戦。 – isherwood