为什么不是我的边距:10px auto;加工? [英] Why isn't my margin:10px auto; working?

查看:104
本文介绍了为什么不是我的边距: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.

这篇关于为什么不是我的边距:10px auto;加工?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆