为什么不是我的边距:10px auto;加工?
问题描述:
由于某种原因,我的父div( #box_one
)通过使用( #box_one {margin:10px auto 10px auto;}
),但是当我尝试相同的技术为它的子元素( #box_one> div
)它只是垂直居中。有人可以解释为什么会发生这种情况吗?
For some reason my parent div ( #box_one
) is being centered in my page perfectly fine by using ( #box_one{ margin: 10px auto 10px auto; }
), but when I try the same technique for it's child element ( #box_one > div
) it only centers it vertically. Can someone explain why this is happening?
<!DOCTYPE html>
<html>
<head>
<title>Text</title>
<style type="text/css">
#box_one{
border: 1px solid black;
width: 400px;
margin: 10px auto 10px auto;
}
#box_one > div{
height: 200px;
border: 1px solid black;
margin: 10px auto 10px auto;
}
</style>
</head>
<body>
<div id="box_one">
<div></div>
</div>
</body>
</html>
答
#box_one> div {} ,你就会变成金色。
Just add a width to #box_one > div{}
and you will be golden.