2013-08-06 151 views
0

当内部div具有静态高度时,什么是垂直对齐另一个div内的div的好方法?至于身高有时会有所不同。 http://jsfiddle.net/daCt3/垂直对齐div中的div?

HTML:

<div id="footer"> 
<div id="footerLeft"> 
<div id="copyright"> 
<!-- <copy> -->Copyright MyCorp &copy; 2013<!-- </copy> --> 
    <br>Some more random stuff 
</div> 
</div> 
<div id="footer-right"> 

</div> 
</div> 

CSS:对于粘性行为

/*-- FOOTER --*/ 

#footer { 
    bottom:0px; 
    width:100%; 
    padding-bottom:20px; 
    padding-top:0px; 
    background-color:#2C2E31; 
    border-top:#242426 solid 2px; 
    position:fixed; 
    height:100px; 

} 

#footerLeft { 
    margin-top:50px; 
    float:left; 
    width:300px; 
    background-color:red; 
} 
+0

你看了其他答案?像这样:http://stackoverflow.com/questions/14879849/vertical-aligned-div?rq=1 – Whistletoe

回答

0

一个解决方案的文章在这里描述

CSS:

#footer { 
    height: 400px; 
    overflow: hidden; 

    /* styling */ 
    bottom:0px;    
    width:100%; 
    background-color:#2C2E31; 
    border-top: #242426 solid 2px; 
    height: 100px; 
    position: fixed; 
} 
#footer[id] { 
    display: table; 
    position: fixed; 
} 

#footerLeft { 
    position: absolute; 
    top: 50%; 
} /* for quirk explorer only*/ 

#footerLeft[id] { 
    display: table-cell; 
    vertical-align: middle; 
    width: 100%; 
    position: static; 
} 

#copyright { 
    position: relative; 
    top: -50%; 

    /* styling */ 
    background: red; 
    width: 300px; 
} /* for quirk explorer only */ 

您可以查看一个例子它在这里:http://jsfiddle.net/UbzcC/1/