简体   繁体   English

div中具有自动边距的HTML CSS div偏离中心吗?

[英]HTML CSS div inside div with auto margin are off-center?

I have a divider that is centered in the page using margin:auto . 我有一个使用margin:auto在页面中心居中的分隔线。 Inside I have two more dividers (can't be combined, must be a divider nested in a divider) when I try to center something inside of this it does not center it in the center of the page. 在内部,当我尝试将某个内容居中居中时,它又有两个分隔符(不能组合,必须是嵌套在分隔符中的分隔符),但它不会居中于页面的中央。 I'm assuming it has to do with the padding-left and padding-right that I've added... Any insight? 我假设它与我添加的padding-leftpadding-right有关...有什么见解吗?

Here's my code: 这是我的代码:

<center>
    <div style="margin:auto; width:80%;">
        <div style="width:50%; padding-left:20%; padding-right:20%;">
            <div style="width:inherit; position:absolute; bottom:0%;">
                <hr />
                test
                <hr />
                <br><br><br>
            </div>
        </div>
    </div>
</center>

Just remove the center tag: 只需删除center标签:

<div style="margin:auto; width:80%;">
    <div style="width:50%; padding-left:20%; padding-right:20%;">
        <div style="width:inherit; position:absolute; bottom:0%;">
            <hr />
            test
            <hr />
            <br><br><br>
        </div>
    </div>
</div>

Check it out here: http://jsfiddle.net/V8qMm/ 在这里查看: http : //jsfiddle.net/V8qMm/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM