divを含むラッパーdiv要素があり、その中にdivが含まれています。これらのdivは、実行時に追加または削除されます。HTMLとCSSは次のようになります。
<div id="Wrapper">
<div class="InnerGreen">
<div class="InnerContent"></div>
<div class="InnerContent"></div>
</div>
</div>
#Wrapper{
width:600px;
height:50px;
margin:10px 20px;
background:blue;}
.InnerGreen{
background:green;
margin:10px auto; // this doesn't center
overflow:hidden;
display:inline-block;}
.InnerContent{
background:yellow;
height:30px;
width:40px;
float:left;
margin:3px 5px;}
私は内側inline-block
を包むために使用しています; ただし、divを水平方向に中央に配置しないようです。もちろん、これは幅を定義すると機能しますが、実際には、divはすべての異なるサイズのdivのコレクションであるため、実行時にの幅を設定することはできません。.InnerGreen
Wrapper
margin:auto
.InnerGreen
.InnerContent
.InnerGreen
どうすればmargin:auto
作品を作ることができますか?ここにjsfiddleがあります。
あなたの提案をありがとう。