Can anyone explain the logic behind this code?
I want to know why making the div#a1
flex allows to center div#a2
by margin:auto 0;
which doesn't work without making div#a1
flex.
#a1{
display:flex;
height: 100px;
width: 100px;
border:3px solid black;
}
#a2{
height: 50px;
width: 50px;
border:3px solid red;
margin: auto 0;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id=a1>
<div id="a2">
</div>
</div>
</body>
</html>