简体   繁体   English

在不使用表格或positoin的情况下将div放在绝对div的底部:absolute

[英]Position a div at the bottom of an absolute div without using tables or positoin:absolute

I am working on a webapp that needs a div to be pushed to the bottom of another absolutely positioned div. 我正在开发一个需要将div推到另一个绝对定位的div底部的webapp。 I have tried bottom: 0 and vertical-align: bottom with neither of them working. 我尝试了bottom: 0vertical-align: bottom ,但它们都不起作用。 Is there some way to move a div to the bottom of its parent div using CSS that I may not have thought of or some sort of workaround that could be done using JavaScript? 是否有某种方法可以使用我可能没有想到的CSS将div移到其父div的底部,或者可以使用JavaScript进行某种变通?

 #wrapper { position: fixed; top: 0; left: 0; height: 100%; width: 100%; background: rgba(0,0,0,0.5); z-index: 1000; } #outer { margin-left: 12.5%; margin-right: 12.5%; margin-top: 5%; margin-bottom: 5%; width: 75%; height: 75%; background: rgb(0, 0, 0); z-index: 1001; } #a { position: absolute; width: inherit; height: 100%; } #inner { bottom: 0; background-color: white; } .invert { color:white; } .revert { color:black; } .text-center { text-align:center; } 
 <div id="wrapper"> <div id="outer" class="invert"> <div id="a"> <h3 class="text-center">Words!</h3> <h4 class="text-center">0 - 0</h4> <div id="inner"> <span class="revert">This needs to be at the bottom</span> </div> </div> </div> </div> 

See code below. 请参见下面的代码。 Also, read up on the position property on MDN . 另外,请阅读MDN上的position属性。

 #wrapper { position: fixed; top: 0; left: 0; height: 100%; width: 100%; background: rgba(0,0,0,0.5); z-index: 1000; } #outer { position: relative; /* <-- add this -------------- */ margin-left: 12.5%; margin-right: 12.5%; margin-top: 5%; margin-bottom: 5%; width: 75%; height: 75%; background: rgb(0, 0, 0); z-index: 1001; } #a { position: absolute; width: inherit; /* <-- change this -------------- */ width: 100%; /* <-- to this -------------- */ height: 100%; } #inner { position: absolute; /* <-- add this -------------- */ width: 100%; /* <-- add this -------------- */ bottom: 0; background-color: white; } .invert { color:white; } .revert { color:black; } .text-center { text-align:center; } 
 <div id="wrapper"> <div id="outer" class="invert"> <div id="a"> <h3 class="text-center">Words!</h3> <h4 class="text-center">0 - 0</h4> <div id="inner"> <span class="revert">This needs to be at the bottom</span> </div> </div> </div> </div> 

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

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