To effortlessly set the width to auto, use margin:0px, auto
#container{
background-color: blue;
height:600px;
width:600px;
margin:0px auto;}
<div id="container"></div>
However, why is it not possible to set the height to auto with margin:auto 0px
? In other words, why doesn't margin: auto 0px;
vertically center a block like margin: 0px auto;
horizontally centers it?
#container{
background-color: blue;
height:600px;
width:600px;
margin:0 auto;}
<div id="container"></div>