イメージ要素は、margin:0px 50px 0px 50px;
で水平にセンタリングすることができます。状況でなぜマージン:0のautoはdivのレベルを中心にすることができませんか?
.wrapper {
width: 175px;
height: 100px;
border: 1px solid red;
}
img {
margin: 0px 50px 0px 50px;
}
<div class="wrapper">
<img src="http://i.imgur.com/9OIT14w.jpg" alt="">
</div>
、margin:0 auto; == margin:0px 50px 0px 50px;
。
margin:0px 50px 0px 50px;
はmargin:0 auto;
と書かれています。
margin:0 auto;
と中央に配置できないのはなぜですか?
.wrapper {
width: 175px;
height: 100px;
border: 1px solid red;
}
img {
margin: 0 auto;
}
<div class="wrapper">
<img src="http://i.imgur.com/9OIT14w.jpg" alt="">
</div>
あなたが一定のマージンを持っているので、それは前のケースで動作し、あなたが要素をインライン化するために、固定マージンを適用することができます。 2番目の例では、 'margin:auto'で要素を中心にするために必要な' display:block'を追加する必要があります。 –