1

这是我的代码,我希望子元素位于其父元素的底部和中心

它在底部还可以,但我无法让它居中

我试过了

text-align:center ;

为父母

margin:0 auto ;

给孩子,但它不起作用

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
                      "http://www.w3.org/TR/html4/strict.dtd">
<html><body>
<div style='background-color: yellow; width: 70%;
            height: 100px; position: relative; text-align:center'>
    Outer

    <div style='background-color: green;
                position: absolute; width: 80%; bottom: 0  ; margin-right:auto ; margin-left:auto ; padding:5px'>
                Inner

    </div>
</div>
</body>
</html>
4

1 回答 1

1

This might answer your question: Centering a percent-based div

Use percentages with your margins.

<div style='background-color: green;
            position: absolute; width: 80%; bottom: 0  ; margin-right:10%; margin-left: 10%; padding:5px'>

Demo: http://jsfiddle.net/DkNdx/

于 2013-05-18T13:19:19.523 回答